[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs tty.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs tty.c |
Date: |
Sat, 12 Apr 2008 19:26:06 +0000 |
CVSROOT: /cvsroot/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 08/04/12 19:26:06
Modified files:
. : tty.c
Log message:
fixed some more tty color issues.
use tty.term_flags for emulation flags
improved cygwin tests
do not use V220 escapes to reset bold and blink
reset char attributes in more places to avoid side effects
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.44&r2=1.45
Patches:
Index: tty.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/tty.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- tty.c 12 Apr 2008 12:40:24 -0000 1.44
+++ tty.c 12 Apr 2008 19:26:05 -0000 1.45
@@ -89,6 +89,9 @@
enum TermCode term_code;
int term_flags;
#define KBS_CONTROL_H 1
+#define USE_BOLD_AS_BRIGHT 2
+#define USE_BLINK_AS_BRIGHT 4
+#define USE_ERASE_END_OF_LINE 8
} TTYState;
static void tty_resize(int sig);
@@ -120,7 +123,7 @@
/* Derive some settings from the TERM environment variable */
tty_state.term_code = TERM_UNKNOWN;
- tty_state.term_flags = 0;
+ tty_state.term_flags = USE_ERASE_END_OF_LINE;
tty_state.term_name = getenv("TERM");
if (tty_state.term_name) {
/* linux and xterm -> kbs=\177
@@ -128,11 +131,11 @@
*/
if (strstart(tty_state.term_name, "ansi", NULL)) {
tty_state.term_code = TERM_ANSI;
- tty_state.term_flags = KBS_CONTROL_H;
+ tty_state.term_flags |= KBS_CONTROL_H;
} else
if (strstart(tty_state.term_name, "vt100", NULL)) {
tty_state.term_code = TERM_VT100;
- tty_state.term_flags = KBS_CONTROL_H;
+ tty_state.term_flags |= KBS_CONTROL_H;
} else
if (strstart(tty_state.term_name, "xterm", NULL)) {
tty_state.term_code = TERM_XTERM;
@@ -142,7 +145,8 @@
} else
if (strstart(tty_state.term_name, "cygwin", NULL)) {
tty_state.term_code = TERM_CYGWIN;
- tty_state.term_flags = KBS_CONTROL_H;
+ tty_state.term_flags |= KBS_CONTROL_H |
+ USE_BOLD_AS_BRIGHT | USE_BLINK_AS_BRIGHT;
}
}
@@ -179,10 +183,15 @@
/* Get charset from command line option */
s->charset = find_charset(qe_state.tty_charset);
+ if (tty_state.term_code == TERM_CYGWIN)
+ s->charset = &charset_8859_1;
+
if (!s->charset && !isatty(fileno(s->STDOUT)))
- s->charset = &charset_utf8;
+ s->charset = &charset_8859_1;
if (!s->charset) {
+ int y, x, n;
+
s->charset = &charset_8859_1;
/* Test UTF8 support by looking at the cursor position (idea
@@ -191,8 +200,6 @@
* sequence in the current locale (ANSI/ISO C99), use a format
* specifier of %s to avoid printf() failing with EILSEQ.
*/
- if (tty_state.term_code != TERM_CYGWIN) {
- int y, x, n;
/* ^X ^Z ^M \170101 */
//printf("%s", "\030\032" "\r\xEF\x81\x81" "\033[6n\033D");
@@ -206,7 +213,6 @@
s->charset = &charset_utf8;
}
}
- }
put_status(NULL, "tty charset: %s", s->charset->name);
atexit(tty_term_exit);
@@ -786,17 +792,8 @@
#endif
};
-#ifdef CONFIG_CYGWIN
-int tty_use_bold_as_bright = 1;
-int tty_use_blink_as_bright = 1;
-unsigned int const *tty_bg_colors = tty_full_colors;
-int tty_bg_colors_count = 8;
-#else
-int tty_use_bold_as_bright = 0;
-int tty_use_blink_as_bright = 0;
unsigned int const *tty_bg_colors = tty_putty_colors;
int tty_bg_colors_count = 16;
-#endif
unsigned int const *tty_fg_colors = tty_putty_colors;
int tty_fg_colors_count = 16;
@@ -1074,9 +1071,15 @@
* difference on row is a space, measure the run of same
* color spaces from the end of the row. If this run
* starts before the last difference, the row is a
- * candidate for a partial update with erase-end-of-line
+ * candidate for a partial update with erase-end-of-line.
+ * exception: do not use erase end of line for a bright
+ * background color if emulated as bright.
*/
- if (TTYCHAR_GETCH(ptr4[-1]) == ' ') {
+ if ((ts->term_flags & USE_ERASE_END_OF_LINE)
+ && TTYCHAR_GETCH(ptr4[-1]) == ' '
+ && (/*!(ts->term_flags & USE_BLINK_AS_BRIGHT) ||*/
+ TTYCHAR_GETBG(ptr4[-1]) < 8))
+ {
/* find the last non blank char on row */
blankcc = TTYCHAR2(' ', TTYCHAR_GETCOL(ptr3[-1]));
while (ptr3 > ptr1 && ptr3[-1] == blankcc) {
@@ -1088,6 +1091,12 @@
*/
if (ptr2 > ptr3 + 3) {
ptr4 = ptr3;
+ /* if the background color changes on the last
+ * space, use the generic loop to synchronize that
+ * space because the color change is non trivial
+ */
+ if (TTYCHAR_GETBG(*ptr3) != TTYCHAR_GETBG(ptr3[-1]))
+ ptr4++;
}
}
@@ -1106,12 +1115,21 @@
ch = TTYCHAR_GETCH(cc);
if (ch != 0xffff) {
/* output attributes */
+ again:
if (bgcolor != (int)TTYCHAR_GETBG(cc)) {
+ int lastbg = bgcolor;
bgcolor = TTYCHAR_GETBG(cc);
- /* should use array of strings */
- if (tty_use_blink_as_bright) {
- TTY_FPRINTF(s->STDOUT, "\033[%dm",
- (bgcolor > 7) ? 5 : 25);
+ if (ts->term_flags & USE_BLINK_AS_BRIGHT) {
+ if (bgcolor > 7) {
+ if (lastbg <= 7) {
+ TTY_FPUTS("\033[5m", s->STDOUT);
+ }
+ } else {
+ if (lastbg > 7) {
+ TTY_FPUTS("\033[0m", s->STDOUT);
+ fgcolor = -1;
+ }
+ }
TTY_FPRINTF(s->STDOUT, "\033[%dm",
40 + (bgcolor & 7));
} else {
@@ -1121,11 +1139,21 @@
}
}
if (fgcolor != (int)TTYCHAR_GETFG(cc) && ch != ' ') {
+ int lastfg = fgcolor;
fgcolor = TTYCHAR_GETFG(cc);
- /* should use array of strings */
- if (tty_use_bold_as_bright) {
- TTY_FPRINTF(s->STDOUT, "\033[%dm",
- (fgcolor > 7) ? 1 : 22);
+ if (ts->term_flags & USE_BOLD_AS_BRIGHT) {
+ if (fgcolor > 7) {
+ if (lastfg <= 7) {
+ TTY_FPUTS("\033[1m", s->STDOUT);
+ }
+ } else {
+ if (lastfg > 7) {
+ TTY_FPUTS("\033[0m", s->STDOUT);
+ fgcolor = -1;
+ bgcolor = -1;
+ goto again;
+ }
+ }
TTY_FPRINTF(s->STDOUT, "\033[%dm",
30 + (fgcolor & 7));
} else {
@@ -1194,19 +1222,24 @@
if (ptr1 < ptr2) {
/* More differences to synch in shadow, erase eol */
cc = *ptr1;
- if (bgcolor != (int)TTYCHAR_GETBG(cc)) {
- bgcolor = TTYCHAR_GETBG(cc);
- TTY_FPRINTF(s->STDOUT, "\033[%dm", 40 + bgcolor);
- }
+ /* the current attribute is already set correctly */
TTY_FPUTS("\033[K", s->STDOUT);
while (ptr1 < ptr2) {
ptr1[shadow] = cc;
ptr1++;
}
}
+// if (ts->term_flags & USE_BLINK_AS_BRIGHT)
+ {
+ if (bgcolor > 7) {
+ TTY_FPUTS("\033[0m", s->STDOUT);
+ fgcolor = bgcolor = -1;
+ }
+ }
}
}
+ TTY_FPUTS("\033[0m", s->STDOUT);
TTY_FPRINTF(s->STDOUT, "\033[%d;%dH", ts->cursor_y + 1, ts->cursor_x + 1);
fflush(s->STDOUT);
}