Skip to content

Commit

Permalink
#89
Browse files Browse the repository at this point in the history
  • Loading branch information
adamyg committed Oct 30, 2024
1 parent 611870b commit cdc7eca
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
50 changes: 34 additions & 16 deletions gr/ttycmd.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <edidentifier.h>
__CIDENT_RCSID(gr_ttycmd_c,"$Id: ttycmd.c,v 1.3 2024/10/09 15:55:49 cvsuser Exp $")
__CIDENT_RCSID(gr_ttycmd_c,"$Id: ttycmd.c,v 1.5 2024/10/30 16:14:09 cvsuser Exp $")

/* -*- mode: c; indent-width: 4; -*- */
/* $Id: ttycmd.c,v 1.3 2024/10/09 15:55:49 cvsuser Exp $
/* $Id: ttycmd.c,v 1.5 2024/10/30 16:14:09 cvsuser Exp $
* TTY common command functions
*
*
Expand Down Expand Up @@ -48,26 +48,45 @@ static int isterm(const char *term, const char *name);
int
tty_defaultscheme(void)
{
const char *fgbg, *term = ggetenv("TERM"); // TODO/TERM_PROGRAM
const char *fgbg, *term = ggetenv("TERM"); // XXX/TERM_PROGRAM
int isdark = 0;

if (term) {
if (isterm(term, "linux") == 0
|| isterm(term, "screen.linux") == 0
|| isterm(term, "cygwin") == 0
|| isterm(term, "putty") == 0
|| isterm(term, "ms-terminal") == 0
|| ggetenv("WT_SESSION")
|| ((fgbg = ggetenv("COLORFGBG")) != NULL && // rxvt, COLORFGBG='0;default;15'
(fgbg = strrchr(fgbg, ';')) != NULL && ((fgbg[1] >= '0' && fgbg[1] <= '6') || fgbg[1] == '8') && fgbg[2] == '\0')) {
if (isterm(term, "linux")
|| isterm(term, "screen.linux")
|| isterm(term, "cygwin")
|| isterm(term, "putty")
|| isterm(term, "ms-terminal")
|| ggetenv("WT_SESSION")) {
isdark = 1;

} else if ((fgbg = ggetenv("COLORFGBG")) != NULL &&
(fgbg = strrchr(fgbg, ';')) != NULL) {
// rxvt style COLORFGBG='0;default;15'
if (((fgbg[1] >= '0' && fgbg[1] <= '6') || fgbg[1] == '8') && fgbg[2] == '\0') {
isdark = 2;
}

} else if (isterm(term, "xterm")) {
switch (x_pt.pt_vtdatype) {
case 0: // putty/msterminal
if (136 == x_pt.pt_vtdaversion || 10 == x_pt.pt_vtdaversion) {
isdark = 3;
}
break;
case 'M': // mintty
isdark = 4;
break;
}
}

} else {
#if defined(WIN32) || defined(__CYGWIN__)
isdark = 1; /* generally dark */
isdark = 5; /* generally dark */
#endif
}
return isdark;
trace_ilog("term_defaultscheme : %d\n", isdark);
return isdark ? 1 : 0;
}


Expand Down Expand Up @@ -231,7 +250,7 @@ tty_luminance(int timeoutms)
*/
if ((XTERM_OCS11_LEN != tty_write(xterm_ocs11, XTERM_OCS11_LEN)) ||
(len = tty_read(buffer, sizeof(buffer), timeoutms)) < 1) {
trace_ilog("ttluminance : io (tm=%d, len=%d)\n", timeoutms, len);
trace_ilog("ttluminance : io (tm=%d, len=%d) : tmr\n", timeoutms, len);
return -1;
}

Expand Down Expand Up @@ -282,7 +301,7 @@ tty_luminance(int timeoutms)
return 0; /* otherwise light */
}

trace_ilog("ttluminance(%d, %s) : n/a", len, buffer);
trace_ilog("ttluminance(%d, %s) : n/a\n", len, buffer);
return -1;
}

Expand Down Expand Up @@ -406,4 +425,3 @@ tty_read(void *ibuffer, int length, int timeoutms)
/*end*/



20 changes: 15 additions & 5 deletions gr/ttyterm.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <edidentifier.h>
__CIDENT_RCSID(gr_ttyterm_c,"$Id: ttyterm.c,v 1.148 2024/10/21 15:03:30 cvsuser Exp $")
__CIDENT_RCSID(gr_ttyterm_c,"$Id: ttyterm.c,v 1.149 2024/10/30 16:14:09 cvsuser Exp $")

/* -*- mode: c; indent-width: 4; -*- */
/* $Id: ttyterm.c,v 1.148 2024/10/21 15:03:30 cvsuser Exp $
/* $Id: ttyterm.c,v 1.149 2024/10/30 16:14:09 cvsuser Exp $
* TTY driver termcap/terminfo based.
*
*
Expand Down Expand Up @@ -2876,8 +2876,11 @@ term_xtermlike(const char *term)
const char *name;
TAttributes_t flags;
} xtermlike[] = {
/*
* many are non-standard, normally represented as "xterm[-256color]"
*/
{ "xterm", TA_XTERM }, /* Generic */
{ "mintty", TA_MINTTY }, /* Non-standard. normally "xterm-256color" */
{ "mintty", TA_MINTTY | TA_DARK },
{ "putty", TA_PUTTY | TA_DARK },
{ "msterminal", TA_MSTERMINAL | TA_DARK },
{ "gnome", TA_GNOME },
Expand Down Expand Up @@ -3501,7 +3504,7 @@ term_identification(void)
* none
*
* Returns:
* 0 on success, otherwise -1 if not available.
* nothing
*/
static int
term_luminance(void)
Expand All @@ -3510,11 +3513,18 @@ term_luminance(void)

if (!tf_XT && 0 == ((TA_XTERM|TA_XTERMLIKE) & t_attributes)) {
trace_ilog("ttluminance : not supported\n");
return -1; /* supported? */
return -1; /* supported */
}

term_flush();
if ((ret = tty_luminance(io_escdelay())) < 0) {
if (0 == ((TA_DARK|TA_LIGHT) & t_attributes)) {
ret = tty_defaultscheme(); /* legacy */
if (ret >= 0) {
t_attributes |= (ret == 1 ? TA_DARK : TA_LIGHT);
return 0;
}
}
return -1;
}

Expand Down

0 comments on commit cdc7eca

Please sign in to comment.