Skip to content

Commit

Permalink
Merge pull request #281 from davidgiven/colours2
Browse files Browse the repository at this point in the history
Add an option to force ncurses not to use colour.
  • Loading branch information
davidgiven authored Dec 28, 2024
2 parents 220cfe5 + 62a84be commit 2a8817b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/c/arch/ncurses/dpy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
static bool use_italics = false;
#endif

static bool enable_colours = true;
static bool use_colours = false;
static int currentAttr = 0;
static short currentPair = 0;
Expand All @@ -32,13 +33,23 @@ typedef struct
static std::vector<colour_t> colours;
static std::vector<pair_t> colourPairs;

void dpy_init(const char* argv[]) {}
void dpy_init(const char* argv[])
{
while (*argv)
{
if (strcmp(*argv, "--no-ncurses-colour") == 0)
enable_colours = false;
if (strcmp(*argv, "--") == 0)
break;
argv++;
}
}

void dpy_start(void)
{
initscr();

use_colours = has_colors() && can_change_color();
use_colours = enable_colours && has_colors() && can_change_color();
if (use_colours)
start_color();

Expand All @@ -62,8 +73,8 @@ void dpy_start(void)

void dpy_shutdown(void)
{
colours.clear();
colourPairs.clear();
colours.clear();
colourPairs.clear();
endwin();
}

Expand Down Expand Up @@ -144,7 +155,7 @@ static uint8_t lookup_colour(const colour_t* colour)
}

uint8_t id = colours.size() + FIRST_COLOUR_ID;
colours.emplace_back(*colour);
colours.emplace_back(*colour);
init_color(id, colour->r * 1000.0, colour->g * 1000.0, colour->b * 1000.0);
return id;
}
Expand All @@ -169,7 +180,7 @@ void dpy_setcolour(const colour_t* fg, const colour_t* bg)
}

currentPair = colourPairs.size() + FIRST_PAIR_ID;
colourPairs.emplace_back(pair_t{fgc, bgc});
colourPairs.emplace_back(pair_t{fgc, bgc});

init_pair(currentPair, fgc, bgc);
update_attrs();
Expand Down
5 changes: 5 additions & 0 deletions src/lua/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ the program starts up (but after any --lua files). It defaults to:
return 0
end

local function do_nothing(arg)
return 0
end

local function unrecognisedarg(arg: string)
CLIError("unrecognised option '", arg, "' --- try --help for help")
assert(false)
Expand All @@ -439,6 +443,7 @@ the program starts up (but after any --lua files). It defaults to:
["8"] = do_8bit,
["r"] = do_recent,
["recent"] = do_recent,
["no-ncurses-colour"] = do_nothing,
[FILENAME_ARG] = do_filename,
[UNKNOWN_ARG] = unrecognisedarg,
}
Expand Down
5 changes: 5 additions & 0 deletions wordgrinder.man
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ Sets the name of the user config file.
Forces 8-bit ISO-8859-1 mode. No Unicode drawing characters are used and
non-ISO-8859-1 characters are drawn as question marks.

.TP
.B --no-ncurses-colour
Forces ncurses not to enable colour support, even if the terminal claims it has
it. This is intended for use when the terminal's colour support is broken.

.TP
.B --recent
On startup, loads the most recent file edited by WordGrinder. If there is no
Expand Down
5 changes: 5 additions & 0 deletions xwordgrinder.man
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ for use when importing or exporting WordGrinder files.
.BI \--config\ file.lua
Sets the name of the user config file.

.TP
.B --recent
On startup, loads the most recent file edited by WordGrinder. If there is no
most recent file, you get an empty document.


.SH CONFIGURATION

Expand Down

0 comments on commit 2a8817b

Please sign in to comment.