Skip to content

Commit

Permalink
true-color
Browse files Browse the repository at this point in the history
#81: true-color/direct, cmdline options
  • Loading branch information
adamyg committed Oct 18, 2024
1 parent a7ca7cc commit ebf534c
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 107 deletions.
2 changes: 1 addition & 1 deletion BUILDNUMBER.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25
27
6 changes: 3 additions & 3 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-*- encoding: utf-8; -*-

Tue Oct 1 22:28:50 2024 adamy
Sun Oct 6 22:29:12 2024 adamy

* Tickets

- Putty profile; #87
- understyles; #72
- true-color; #81
- understyles and strikeout; #72

Thu Sep 26 21:27:49 2024 adamy

Expand Down
39 changes: 28 additions & 11 deletions gr/cmain.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <edidentifier.h>
__CIDENT_RCSID(gr_cmain_c,"$Id: cmain.c,v 1.68 2024/10/06 17:01:22 cvsuser Exp $")
__CIDENT_RCSID(gr_cmain_c,"$Id: cmain.c,v 1.69 2024/10/18 05:19:14 cvsuser Exp $")

/* -*- mode: c; indent-width: 4; -*- */
/* $Id: cmain.c,v 1.68 2024/10/06 17:01:22 cvsuser Exp $
/* $Id: cmain.c,v 1.69 2024/10/18 05:19:14 cvsuser Exp $
* Main body, startup and command-line processing.
*
*
Expand Down Expand Up @@ -131,7 +131,7 @@ static struct argoption options[] = {
{ "noscroll", arg_none, NULL, 2, "Disable xterm scrolling" },

{ "color", arg_optional, NULL, 3, "Color depth/mode",
"=<depth>|<truecolor>|<none>" },
"=<depth>|<truecolor>|<direct>|<none>" },

{ "nocolor", arg_none, NULL, 3, "Force black and white display" },

Expand Down Expand Up @@ -317,7 +317,7 @@ int xf_spell = -1; /* TRUE/FALSE/-1 enable spell. *
/* TRUE enables tty regions scrolling. */
int xf_scrollregions = FALSE;

int xf_color = -1; /* TRUE/FALSE, user specified color mode. */
int xf_color = COLORMODE_AUTO; /* color depth/mode. */

int xf_graph = -1; /* TRUE/FALSE, user specified graphic mode. */

Expand Down Expand Up @@ -1014,15 +1014,28 @@ argv_process(const int doerr, int argc, const char **argv)

case 3: /* tty - [no]color=[depth] */
if ('c' == args.opt) {
if (args.val && 0 == strcmp(args.val, "none")) {
xf_color = 0;
} else if (args.val && (0 == strcmp(args.val, "truecolor") || 0 == strcmp(args.val, "24bit"))) {
xf_color = INT_MAX;
} else if (! args.val || (xf_color = atoi(args.val)) <= 0) {
xf_color = 1;
if (! args.val || 0 == strcmp(args.val, "auto")) {
xf_color = COLORMODE_AUTO;
} else if (0 == strcmp(args.val, "none")) {
xf_color = COLORMODE_NONE;
} else if (0 == strcmp(args.val, "truecolor") || 0 == strcmp(args.val, "24bit")) {
xf_color = COLORMODE_TRUECOLOR; // semicolon
} else if (0 == strcmp(args.val, "direct")) {
xf_color = COLORMODE_DIRECT; // colon
} else {
xf_color = (int)strtoul(args.val, NULL, 10);
if (xf_color >= COLORMODE_256) {
xf_color = COLORMODE_256;
} else if (xf_color >= COLORMODE_88) {
xf_color = COLORMODE_88;
} else if (xf_color >= COLORMODE_16) {
xf_color = COLORMODE_16;
} else if (xf_color >= 1) {
xf_color = COLORMODE_8;
}
}
} else {
xf_color = 0;
xf_color = COLORMODE_NONE;
}
break;

Expand Down Expand Up @@ -2101,3 +2114,7 @@ usage(int what)
}

/*end*/




6 changes: 3 additions & 3 deletions gr/display.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <edidentifier.h>
__CIDENT_RCSID(gr_display_c,"$Id: display.c,v 1.88 2024/09/12 17:28:50 cvsuser Exp $")
__CIDENT_RCSID(gr_display_c,"$Id: display.c,v 1.89 2024/10/18 05:19:14 cvsuser Exp $")

/* -*- mode: c; indent-width: 4; -*- */
/* $Id: display.c,v 1.88 2024/09/12 17:28:50 cvsuser Exp $
/* $Id: display.c,v 1.89 2024/10/18 05:19:14 cvsuser Exp $
* High level display interface.
*
*
Expand Down Expand Up @@ -588,7 +588,7 @@ vtupdating(void)
int
vtiscolor(void)
{
if (-1 != xf_color) {
if (COLORMODE_AUTO != xf_color) {
return xf_color; /* user override */
}
return x_pt.pt_color; /* ... otherwise terminal specific */
Expand Down
16 changes: 12 additions & 4 deletions gr/main.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef GR_MAIN_H_INCLUDED
#define GR_MAIN_H_INCLUDED
#include <edidentifier.h>
__CIDENT_RCSID(gr_main_h,"$Id: main.h,v 1.34 2024/10/01 12:54:54 cvsuser Exp $")
__CIDENT_RCSID(gr_main_h,"$Id: main.h,v 1.35 2024/10/18 05:19:14 cvsuser Exp $")
__CPRAGMA_ONCE

/* -*- mode: c; indent-width: 4; -*- */
/* $Id: main.h,v 1.34 2024/10/01 12:54:54 cvsuser Exp $
/* $Id: main.h,v 1.35 2024/10/18 05:19:14 cvsuser Exp $
* Globals and main process primitives.
*
*
Expand Down Expand Up @@ -51,7 +51,16 @@ extern int xf_spell; /* TRUE/FALSE/-1 enable spell. *

extern int xf_scrollregions; /* TRUE/FALSE, enable scroll regions. */

extern int xf_color; /* TRUE/FALSE, use color override. */
#define COLORMODE_AUTO -1
#define COLORMODE_NONE 0
#define COLORMODE_8 8
#define COLORMODE_16 16
#define COLORMODE_88 88
#define COLORMODE_256 256
#define COLORMODE_TRUECOLOR 1000
#define COLORMODE_DIRECT 1001

extern int xf_color; /* color-mode override, default=COLORMODE_AUTO. */

extern int xf_graph; /* TRUE/FALSE, user specified graphic mode. */

Expand Down Expand Up @@ -143,4 +152,3 @@ extern void do_suspend(void);
__CEND_DECLS

#endif /*GR_MAIN_H_INCLUDED*/

32 changes: 15 additions & 17 deletions gr/ttyncurses.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <edidentifier.h>
__CIDENT_RCSID(gr_ttyncurses_c,"$Id: ttyncurses.c,v 1.33 2024/10/15 13:49:55 cvsuser Exp $")
__CIDENT_RCSID(gr_ttyncurses_c,"$Id: ttyncurses.c,v 1.34 2024/10/18 05:19:14 cvsuser Exp $")

/* -*- mode: c; indent-width: 4; -*- */
/* $Id: ttyncurses.c,v 1.33 2024/10/15 13:49:55 cvsuser Exp $
/* $Id: ttyncurses.c,v 1.34 2024/10/18 05:19:14 cvsuser Exp $
* [n]curses tty driver interface -- alt driver when running under ncurses.
*
* This file is part of the GRIEF Editor.
Expand Down Expand Up @@ -834,7 +834,7 @@ istruecolor(void)
{
#if defined(CURSES_DIRECT_COLORS)
if (COLORS == DIRECT_COLORS) {
return 1; /* direct RGB support. */
return COLORIF_DIRECT; /* direct RGB support. */
}
#endif
return 0;
Expand Down Expand Up @@ -1119,8 +1119,10 @@ term_colors(void)
{
int truecolor = 0;

tt_colors = 2; // black&white

#if defined(A_COLOR)
if (xf_color > 1 || (-1 == xf_color && has_colors()) ||
if (xf_color >= COLORMODE_8 || (COLORMODE_AUTO == xf_color && has_colors()) ||
x_pt.pt_colordepth > 1) {

tt_defaultfg = COLOR_WHITE;
Expand All @@ -1129,15 +1131,7 @@ term_colors(void)
start_color();
tt_colors = COLORS;

#if defined(CURSES_DIRECT_COLORS)
if (COLORS == DIRECT_COLORS) { // direct, overlap count
if ((tt_direct = tigetnum(CURSES_CAST("CO"))) <= 0) {
tt_direct = 1;
}
}
#endif

if (xf_color == -1 || xf_color == INT_MAX) {
if (xf_color == COLORMODE_AUTO || xf_color > COLORMODE_256) {
truecolor = istruecolor(); // enable if supported
} else if (tt_colors > xf_color) {
tt_colors = xf_color; // limit to configuration
Expand All @@ -1154,13 +1148,16 @@ term_colors(void)
} else if (OK == use_default_colors()) {
tt_defaultfg = tt_defaultbg = -1;
}
}

} else {
tt_colors = 2;
#if defined(CURSES_DIRECT_COLORS)
if (COLORS == DIRECT_COLORS) { // direct, overlap count
if ((tt_direct = tigetnum(CURSES_CAST("CO"))) <= 0) {
tt_direct = 1;
}
}
#else
tt_colors = 2;
#endif
#endif //A_COLOR

trace_log("ttync: colors(depth:%d,truecolor:%d,fg:%d,bg:%d)\n", tt_colors, truecolor, tt_defaultfg, tt_defaultbg);

Expand Down Expand Up @@ -1369,3 +1366,4 @@ term_tidy(void)
#endif /*HAVE_LIBNCURSES*/

/*end*/

Loading

0 comments on commit ebf534c

Please sign in to comment.