Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to force ncurses not to use colour. #281

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading