qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs qe.h shell.c tty.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs qe.h shell.c tty.c
Date: Tue, 08 Apr 2008 19:57:34 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        08/04/08 19:57:33

Modified files:
        .              : qe.h shell.c tty.c 

Log message:
        handle upto 16 colors in console output and shell terminal
        simulate xterm 256 colors in terminal
        improved bold trick

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.78&r2=1.79
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.50&r2=1.51
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.39&r2=1.40

Patches:
Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -b -r1.78 -r1.79
--- qe.h        8 Apr 2008 09:25:16 -0000       1.78
+++ qe.h        8 Apr 2008 19:57:33 -0000       1.79
@@ -1078,16 +1078,20 @@
 
 /* special bit to indicate tty styles (for shell mode) */
 #define QE_STYLE_TTY       0x800
-#define TTY_BOLD           (1 << 6)
-#define TTY_FG_COLOR(fg)   ((fg) << 3)
-#define TTY_BG_COLOR(bg)   (bg)
-#define TTY_GET_COLOR(fg, bg)  (((fg) << 3) | (bg))
-#define TTY_GET_XFG(color) (((color) >> 3) & 15)
-#define TTY_GET_FG(color)  (((color) >> 3) & 7)
-#define TTY_GET_BG(color)  ((color) & 7)
-
-extern unsigned int const tty_bg_colors[]; /* from tty.c */
-extern unsigned int const tty_fg_colors[];
+#define TTY_BOLD           (1 << 7)
+#define TTY_MAKE_COLOR(fg, bg)  (((fg) << 4) | (bg))
+#define TTY_SET_FG_COLOR(color, fg)   ((color) = ((color) & ~(15 << 4)) | 
((fg) << 4))
+#define TTY_SET_BG_COLOR(color, bg)   ((color) = ((color) & ~(15)) | ((bg)))
+#define TTY_GET_XFG(color) (((color) >> 4) & 15)
+#define TTY_GET_FG(color)  (((color) >> 4) & 7)
+#define TTY_GET_BG(color)  (((color) >> 0) & 15)
+
+/* from tty.c */
+extern unsigned int const *tty_bg_colors;
+extern int tty_bg_colors_count;
+extern unsigned int const *tty_fg_colors;
+extern int tty_fg_colors_count;
+int get_tty_color(QEColor color, unsigned int const *colors, int count);
 
 /* special selection style (cumulative with another style) */
 #define QE_STYLE_SEL     0x400

Index: shell.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/shell.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- shell.c     8 Apr 2008 09:33:18 -0000       1.50
+++ shell.c     8 Apr 2008 19:57:33 -0000       1.51
@@ -55,7 +55,7 @@
     /* buffer state */
     int pty_fd;
     int pid; /* -1 if not launched */
-    int color, def_color;
+    int color, bold, def_color;
     int cur_offset; /* current offset at position x, y */
     int esc_params[MAX_ESC_PARAMS];
     int has_params[MAX_ESC_PARAMS];
@@ -188,8 +188,11 @@
 
     s->state = TTY_STATE_NORM;
     s->cur_offset = 0;
-    s->def_color = TTY_GET_COLOR(7, 0);
-    s->color = s->def_color;
+    /* Should compute def_color from shell default style at display
+     * time and force full redisplay upon style change.
+     */
+    s->color = s->def_color = TTY_MAKE_COLOR(7, 0);
+    s->bold = 0;
 
     term = getenv("TERM");
     /* vt100 terminfo definitions */
@@ -446,45 +449,51 @@
     switch (has_param ? c : 0) {
     case 0:     /* exit_attribute_mode */
         s->color = s->def_color;
+        s->bold = 0;
         break;
     case 1:     /* enter_bold_mode */
-        s->color |= TTY_BOLD;
+        s->bold = TTY_BOLD;
         break;
     case 22:    /* exit_bold_mode */
-        s->color &= ~TTY_BOLD;
+        s->bold = 0;
         break;
-    case 4:     /* enter_underline_mode */
-    case 5:     /* enter_blink_mode */
     case 7:     /* enter_reverse_mode, enter_standout_mode */
-    case 8:     /* enter_secure_mode */
+    case 27:    /* exit_reverse_mode, exit_standout_mode */
+        /* TODO */
+        break;
+    case 4:     /* enter_underline_mode */
     case 24:    /* exit_underline_mode */
+    case 5:     /* enter_blink_mode */
     case 25:    /* exit_blink_mode */
-    case 27:    /* exit_reverse_mode, exit_standout_mode */
+    case 8:     /* enter_secure_mode */
     case 28:    /* exit_secure_mode */
     case 39:    /* orig_pair(1) */
     case 49:    /* orig_pair(2) */
         break;
-    case 38:    /* set extended foreground color ? */
-        /* complete syntax is \033[38;5;Nm where N is the index from 1
-         * to 255.
-         */
+    case 38:    /* set extended foreground color */
+        /* complete syntax is \033[38;5;Nm where N is in range 1..255 */
         if (s->esc_params[1] == 5) {
             /* set foreground color to third esc_param */
-            /* should support 256 colors */
-            s->color &= ~TTY_FG_COLOR(15);
-            s->color |= TTY_FG_COLOR(s->esc_params[2] & 15);
+            int color = s->esc_params[2];
+
+            /* simulate 256 colors */
+            color = get_tty_color(tty_fg_colors[color & 255],
+                                  tty_fg_colors, 16);
+
+            TTY_SET_FG_COLOR(s->color, color);
             s->nb_esc_params = 1;
         }
         break;
-    case 48:    /* set extended background color ? */
-        /* complete syntax is \033[48;5;Nm where N is the index from 1
-         * to 255.
-         */
+    case 48:    /* set extended background color */
+        /* complete syntax is \033[48;5;Nm where N is in range 1..255 */
         if (s->esc_params[1] == 5) {
-            /* set foreground color to third esc_param */
-            /* should support 256 colors */
-            s->color &= ~TTY_BG_COLOR(7);
-            s->color |= TTY_BG_COLOR(s->esc_params[2] & 7);
+            /* set background color to third esc_param */
+            int color = s->esc_params[2];
+
+            /* simulate 256 colors */
+            color = get_tty_color(tty_fg_colors[color & 255],
+                                  tty_fg_colors, 16);
+            TTY_SET_BG_COLOR(s->color, color);
             s->nb_esc_params = 1;
         }
         break;
@@ -492,23 +501,19 @@
         /* 0:black 1:red 2:green 3:yellow 4:blue 5:magenta 6:cyan 7:white */
         if (c >= 30 && c <= 37) {
             /* set foreground color */
-            s->color &= ~TTY_FG_COLOR(7);
-            s->color |= TTY_FG_COLOR(c - 30);
+            TTY_SET_FG_COLOR(s->color, c - 30);
         } else
         if (c >= 40 && c <= 47) {
             /* set background color */
-            s->color &= ~TTY_BG_COLOR(7);
-            s->color |= TTY_BG_COLOR(c - 40);
+            TTY_SET_BG_COLOR(s->color, c - 40);
         } else
         if (c >= 90 && c <= 97) {
             /* set bright foreground color */
-            s->color &= ~TTY_FG_COLOR(15);
-            s->color |= TTY_FG_COLOR(c - 90 + 8);
+            TTY_SET_FG_COLOR(s->color, c - 90 + 8);
         } else
         if (c >= 100 && c <= 107) {
-            /* set bright background color (NYI) */
-            s->color &= ~TTY_BG_COLOR(7);
-            s->color |= TTY_BG_COLOR(c - 100);
+            /* set bright background color */
+            TTY_SET_BG_COLOR(s->color, c - 100 + 8);
         }
         break;
     }
@@ -809,7 +814,7 @@
         }
         /* Stop string on \a (^G) or M-\ -- need better test for ESC \ */
         if (c == '\007' || c == 0234 || c == '\\') {
-            /* CG: ESC2(']','0') should store window caption */
+            /* CG: ESC2(']','0') should set shell caption */
             /* CG: ESC2(']','4') should parse color definition string */
             /* (example: "\033]4;16;rgb:00/00/00\033\134" ) */
             s->state = TTY_STATE_NORM;
@@ -863,12 +868,10 @@
                 }
                 break;
             case ESC2('=','F'): /* select SCO foreground color */
-                s->color &= ~TTY_FG_COLOR(15);
-                s->color |= TTY_FG_COLOR(sco_color[s->esc_params[0] & 15]);
+                TTY_SET_FG_COLOR(s->color, sco_color[s->esc_params[0] & 15]);
                 break;
             case ESC2('=','G'): /* select SCO background color */
-                s->color &= ~TTY_BG_COLOR(7);
-                s->color |= TTY_BG_COLOR(sco_color[s->esc_params[0] & 7]);
+                TTY_SET_BG_COLOR(s->color, sco_color[s->esc_params[0] & 15]);
                 break;
             case 'A':
                 /* move relative up */
@@ -982,7 +985,7 @@
             len = size;
             if (len > ssizeof(buf))
                 len = ssizeof(buf);
-            memset(buf, s->color, len);
+            memset(buf, s->color | s->bold, len);
             eb_write(s->b_color, offset, buf, len);
             size -= len;
             offset += len;
@@ -993,7 +996,7 @@
             len = size;
             if (len > ssizeof(buf))
                 len = ssizeof(buf);
-            memset(buf, s->color, len);
+            memset(buf, s->color | s->bold, len);
             eb_insert(s->b_color, offset, buf, len);
             size -= len;
             offset += len;
@@ -1031,7 +1034,8 @@
                 eb_read(b_color, offset, buf1, 1);
                 color = buf1[0];
                 /* XXX: test */
-                if (color != s->def_color) {
+                //if (color != s->def_color)
+                {
                     c |= (QE_STYLE_TTY | color) << STYLE_SHIFT;
                 }
             }
@@ -1137,7 +1141,8 @@
                shells) */
             kill(s->pid, SIGKILL);
             /* CG: should add timeout facility and error message */
-            while (waitpid(s->pid, &status, 0) != s->pid);
+            while (waitpid(s->pid, &status, 0) != s->pid)
+                continue;
         }
         s->pid = -1;
     }

Index: tty.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/tty.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- tty.c       4 Apr 2008 09:56:17 -0000       1.39
+++ tty.c       8 Apr 2008 19:57:33 -0000       1.40
@@ -40,7 +40,7 @@
 #define TTYCHAR_GETCOL(cc)  (((cc) >> 16) & 0xFFFF)
 #define TTYCHAR_GETFG(cc)   (((cc) >> 16) & 0xFF)
 #define TTYCHAR_GETBG(cc)   (((cc) >> 24) & 0xFF)
-#define TTYCHAR_DEFAULT     TTYCHAR(' ', 0, 0)
+#define TTYCHAR_DEFAULT     TTYCHAR(' ', 7, 0)
 
 #if defined(__GNUC__) && !defined(CONFIG_CYGWIN)
 #  define TTY_PUTC(c,f)         putc_unlocked(c, f)
@@ -505,15 +505,8 @@
     }
 }
 
-static inline int color_dist(unsigned int c1, unsigned c2)
-{
-
-    return (abs( (c1 & 0xff) - (c2 & 0xff)) +
-            2 * abs( ((c1 >> 8) & 0xff) - ((c2 >> 8) & 0xff)) +
-            abs( ((c1 >> 16) & 0xff) - ((c2 >> 16) & 0xff)));
-}
-
-unsigned int const tty_bg_colors[8] = {
+#if 0
+unsigned int const tty_full_colors[8] = {
     QERGB(0x00, 0x00, 0x00),
     QERGB(0xff, 0x00, 0x00),
     QERGB(0x00, 0xff, 0x00),
@@ -523,8 +516,9 @@
     QERGB(0x00, 0xff, 0xff),
     QERGB(0xff, 0xff, 0xff),
 };
+#endif
 
-unsigned int const tty_fg_colors[16] = {
+unsigned int const tty_putty_colors[256] = {
     QERGB(0x00, 0x00, 0x00),
     QERGB(0xbb, 0x00, 0x00),
     QERGB(0x00, 0xbb, 0x00),
@@ -542,9 +536,272 @@
     QERGB(0xff, 0x55, 0xff),
     QERGB(0x55, 0xff, 0xff),
     QERGB(0xff, 0xff, 0xff),
+#if 1
+    /* Extended color palette for xterm 256 color mode */
+
+    /* From XFree86: xc/programs/xterm/256colres.h,
+     * v 1.5 2002/10/05 17:57:11 dickey Exp
+     */
+
+    /* 216 entry RGB cube with axes 0,95,135,175,215,255 */
+    /* followed by 24 entry grey scale 8,18..238 */
+    QERGB(0x00, 0x00, 0x00),  /* 16: Grey0 */
+    QERGB(0x00, 0x00, 0x5f),  /* 17: NavyBlue */
+    QERGB(0x00, 0x00, 0x87),  /* 18: DarkBlue */
+    QERGB(0x00, 0x00, 0xaf),  /* 19: Blue3 */
+    QERGB(0x00, 0x00, 0xd7),  /* 20: Blue3 */
+    QERGB(0x00, 0x00, 0xff),  /* 21: Blue1 */
+    QERGB(0x00, 0x5f, 0x00),  /* 22: DarkGreen */
+    QERGB(0x00, 0x5f, 0x5f),  /* 23: DeepSkyBlue4 */
+    QERGB(0x00, 0x5f, 0x87),  /* 24: DeepSkyBlue4 */
+    QERGB(0x00, 0x5f, 0xaf),  /* 25: DeepSkyBlue4 */
+    QERGB(0x00, 0x5f, 0xd7),  /* 26: DodgerBlue3 */
+    QERGB(0x00, 0x5f, 0xff),  /* 27: DodgerBlue2 */
+    QERGB(0x00, 0x87, 0x00),  /* 28: Green4 */
+    QERGB(0x00, 0x87, 0x5f),  /* 29: SpringGreen4 */
+    QERGB(0x00, 0x87, 0x87),  /* 30: Turquoise4 */
+    QERGB(0x00, 0x87, 0xaf),  /* 31: DeepSkyBlue3 */
+    QERGB(0x00, 0x87, 0xd7),  /* 32: DeepSkyBlue3 */
+    QERGB(0x00, 0x87, 0xff),  /* 33: DodgerBlue1 */
+    QERGB(0x00, 0xaf, 0x00),  /* 34: Green3 */
+    QERGB(0x00, 0xaf, 0x5f),  /* 35: SpringGreen3 */
+    QERGB(0x00, 0xaf, 0x87),  /* 36: DarkCyan */
+    QERGB(0x00, 0xaf, 0xaf),  /* 37: LightSeaGreen */
+    QERGB(0x00, 0xaf, 0xd7),  /* 38: DeepSkyBlue2 */
+    QERGB(0x00, 0xaf, 0xff),  /* 39: DeepSkyBlue1 */
+    QERGB(0x00, 0xd7, 0x00),  /* 40: Green3 */
+    QERGB(0x00, 0xd7, 0x5f),  /* 41: SpringGreen3 */
+    QERGB(0x00, 0xd7, 0x87),  /* 42: SpringGreen2 */
+    QERGB(0x00, 0xd7, 0xaf),  /* 43: Cyan3 */
+    QERGB(0x00, 0xd7, 0xd7),  /* 44: DarkTurquoise */
+    QERGB(0x00, 0xd7, 0xff),  /* 45: Turquoise2 */
+    QERGB(0x00, 0xff, 0x00),  /* 46: Green1 */
+    QERGB(0x00, 0xff, 0x5f),  /* 47: SpringGreen2 */
+    QERGB(0x00, 0xff, 0x87),  /* 48: SpringGreen1 */
+    QERGB(0x00, 0xff, 0xaf),  /* 49: MediumSpringGreen */
+    QERGB(0x00, 0xff, 0xd7),  /* 50: Cyan2 */
+    QERGB(0x00, 0xff, 0xff),  /* 51: Cyan1 */
+    QERGB(0x5f, 0x00, 0x00),  /* 52: DarkRed */
+    QERGB(0x5f, 0x00, 0x5f),  /* 53: DeepPink4 */
+    QERGB(0x5f, 0x00, 0x87),  /* 54: Purple4 */
+    QERGB(0x5f, 0x00, 0xaf),  /* 55: Purple4 */
+    QERGB(0x5f, 0x00, 0xd7),  /* 56: Purple3 */
+    QERGB(0x5f, 0x00, 0xff),  /* 57: BlueViolet */
+    QERGB(0x5f, 0x5f, 0x00),  /* 58: Orange4 */
+    QERGB(0x5f, 0x5f, 0x5f),  /* 59: Grey37 */
+    QERGB(0x5f, 0x5f, 0x87),  /* 60: MediumPurple4 */
+    QERGB(0x5f, 0x5f, 0xaf),  /* 61: SlateBlue3 */
+    QERGB(0x5f, 0x5f, 0xd7),  /* 62: SlateBlue3 */
+    QERGB(0x5f, 0x5f, 0xff),  /* 63: RoyalBlue1 */
+    QERGB(0x5f, 0x87, 0x00),  /* 64: Chartreuse4 */
+    QERGB(0x5f, 0x87, 0x5f),  /* 65: DarkSeaGreen4 */
+    QERGB(0x5f, 0x87, 0x87),  /* 66: PaleTurquoise4 */
+    QERGB(0x5f, 0x87, 0xaf),  /* 67: SteelBlue */
+    QERGB(0x5f, 0x87, 0xd7),  /* 68: SteelBlue3 */
+    QERGB(0x5f, 0x87, 0xff),  /* 69: CornflowerBlue */
+    QERGB(0x5f, 0xaf, 0x00),  /* 70: Chartreuse3 */
+    QERGB(0x5f, 0xaf, 0x5f),  /* 71: DarkSeaGreen4 */
+    QERGB(0x5f, 0xaf, 0x87),  /* 72: CadetBlue */
+    QERGB(0x5f, 0xaf, 0xaf),  /* 73: CadetBlue */
+    QERGB(0x5f, 0xaf, 0xd7),  /* 74: SkyBlue3 */
+    QERGB(0x5f, 0xaf, 0xff),  /* 75: SteelBlue1 */
+    QERGB(0x5f, 0xd7, 0x00),  /* 76: Chartreuse3 */
+    QERGB(0x5f, 0xd7, 0x5f),  /* 77: PaleGreen3 */
+    QERGB(0x5f, 0xd7, 0x87),  /* 78: SeaGreen3 */
+    QERGB(0x5f, 0xd7, 0xaf),  /* 79: Aquamarine3 */
+    QERGB(0x5f, 0xd7, 0xd7),  /* 80: MediumTurquoise */
+    QERGB(0x5f, 0xd7, 0xff),  /* 81: SteelBlue1 */
+    QERGB(0x5f, 0xff, 0x00),  /* 82: Chartreuse2 */
+    QERGB(0x5f, 0xff, 0x5f),  /* 83: SeaGreen2 */
+    QERGB(0x5f, 0xff, 0x87),  /* 84: SeaGreen1 */
+    QERGB(0x5f, 0xff, 0xaf),  /* 85: SeaGreen1 */
+    QERGB(0x5f, 0xff, 0xd7),  /* 86: Aquamarine1 */
+    QERGB(0x5f, 0xff, 0xff),  /* 87: DarkSlateGray2 */
+    QERGB(0x87, 0x00, 0x00),  /* 88: DarkRed */
+    QERGB(0x87, 0x00, 0x5f),  /* 89: DeepPink4 */
+    QERGB(0x87, 0x00, 0x87),  /* 90: DarkMagenta */
+    QERGB(0x87, 0x00, 0xaf),  /* 91: DarkMagenta */
+    QERGB(0x87, 0x00, 0xd7),  /* 92: DarkViolet */
+    QERGB(0x87, 0x00, 0xff),  /* 93: Purple */
+    QERGB(0x87, 0x5f, 0x00),  /* 94: Orange4 */
+    QERGB(0x87, 0x5f, 0x5f),  /* 95: LightPink4 */
+    QERGB(0x87, 0x5f, 0x87),  /* 96: Plum4 */
+    QERGB(0x87, 0x5f, 0xaf),  /* 97: MediumPurple3 */
+    QERGB(0x87, 0x5f, 0xd7),  /* 98: MediumPurple3 */
+    QERGB(0x87, 0x5f, 0xff),  /* 99: SlateBlue1 */
+    QERGB(0x87, 0x87, 0x00),  /* 100: Yellow4 */
+    QERGB(0x87, 0x87, 0x5f),  /* 101: Wheat4 */
+    QERGB(0x87, 0x87, 0x87),  /* 102: Grey53 */
+    QERGB(0x87, 0x87, 0xaf),  /* 103: LightSlateGrey */
+    QERGB(0x87, 0x87, 0xd7),  /* 104: MediumPurple */
+    QERGB(0x87, 0x87, 0xff),  /* 105: LightSlateBlue */
+    QERGB(0x87, 0xaf, 0x00),  /* 106: Yellow4 */
+    QERGB(0x87, 0xaf, 0x5f),  /* 107: DarkOliveGreen3 */
+    QERGB(0x87, 0xaf, 0x87),  /* 108: DarkSeaGreen */
+    QERGB(0x87, 0xaf, 0xaf),  /* 109: LightSkyBlue3 */
+    QERGB(0x87, 0xaf, 0xd7),  /* 110: LightSkyBlue3 */
+    QERGB(0x87, 0xaf, 0xff),  /* 111: SkyBlue2 */
+    QERGB(0x87, 0xd7, 0x00),  /* 112: Chartreuse2 */
+    QERGB(0x87, 0xd7, 0x5f),  /* 113: DarkOliveGreen3 */
+    QERGB(0x87, 0xd7, 0x87),  /* 114: PaleGreen3 */
+    QERGB(0x87, 0xd7, 0xaf),  /* 115: DarkSeaGreen3 */
+    QERGB(0x87, 0xd7, 0xd7),  /* 116: DarkSlateGray3 */
+    QERGB(0x87, 0xd7, 0xff),  /* 117: SkyBlue1 */
+    QERGB(0x87, 0xff, 0x00),  /* 118: Chartreuse1 */
+    QERGB(0x87, 0xff, 0x5f),  /* 119: LightGreen */
+    QERGB(0x87, 0xff, 0x87),  /* 120: LightGreen */
+    QERGB(0x87, 0xff, 0xaf),  /* 121: PaleGreen1 */
+    QERGB(0x87, 0xff, 0xd7),  /* 122: Aquamarine1 */
+    QERGB(0x87, 0xff, 0xff),  /* 123: DarkSlateGray1 */
+    QERGB(0xaf, 0x00, 0x00),  /* 124: Red3 */
+    QERGB(0xaf, 0x00, 0x5f),  /* 125: DeepPink4 */
+    QERGB(0xaf, 0x00, 0x87),  /* 126: MediumVioletRed */
+    QERGB(0xaf, 0x00, 0xaf),  /* 127: Magenta3 */
+    QERGB(0xaf, 0x00, 0xd7),  /* 128: DarkViolet */
+    QERGB(0xaf, 0x00, 0xff),  /* 129: Purple */
+    QERGB(0xaf, 0x5f, 0x00),  /* 130: DarkOrange3 */
+    QERGB(0xaf, 0x5f, 0x5f),  /* 131: IndianRed */
+    QERGB(0xaf, 0x5f, 0x87),  /* 132: HotPink3 */
+    QERGB(0xaf, 0x5f, 0xaf),  /* 133: MediumOrchid3 */
+    QERGB(0xaf, 0x5f, 0xd7),  /* 134: MediumOrchid */
+    QERGB(0xaf, 0x5f, 0xff),  /* 135: MediumPurple2 */
+    QERGB(0xaf, 0x87, 0x00),  /* 136: DarkGoldenrod */
+    QERGB(0xaf, 0x87, 0x5f),  /* 137: LightSalmon3 */
+    QERGB(0xaf, 0x87, 0x87),  /* 138: RosyBrown */
+    QERGB(0xaf, 0x87, 0xaf),  /* 139: Grey63 */
+    QERGB(0xaf, 0x87, 0xd7),  /* 140: MediumPurple2 */
+    QERGB(0xaf, 0x87, 0xff),  /* 141: MediumPurple1 */
+    QERGB(0xaf, 0xaf, 0x00),  /* 142: Gold3 */
+    QERGB(0xaf, 0xaf, 0x5f),  /* 143: DarkKhaki */
+    QERGB(0xaf, 0xaf, 0x87),  /* 144: NavajoWhite3 */
+    QERGB(0xaf, 0xaf, 0xaf),  /* 145: Grey69 */
+    QERGB(0xaf, 0xaf, 0xd7),  /* 146: LightSteelBlue3 */
+    QERGB(0xaf, 0xaf, 0xff),  /* 147: LightSteelBlue */
+    QERGB(0xaf, 0xd7, 0x00),  /* 148: Yellow3 */
+    QERGB(0xaf, 0xd7, 0x5f),  /* 149: DarkOliveGreen3 */
+    QERGB(0xaf, 0xd7, 0x87),  /* 150: DarkSeaGreen3 */
+    QERGB(0xaf, 0xd7, 0xaf),  /* 151: DarkSeaGreen2 */
+    QERGB(0xaf, 0xd7, 0xd7),  /* 152: LightCyan3 */
+    QERGB(0xaf, 0xd7, 0xff),  /* 153: LightSkyBlue1 */
+    QERGB(0xaf, 0xff, 0x00),  /* 154: GreenYellow */
+    QERGB(0xaf, 0xff, 0x5f),  /* 155: DarkOliveGreen2 */
+    QERGB(0xaf, 0xff, 0x87),  /* 156: PaleGreen1 */
+    QERGB(0xaf, 0xff, 0xaf),  /* 157: DarkSeaGreen2 */
+    QERGB(0xaf, 0xff, 0xd7),  /* 158: DarkSeaGreen1 */
+    QERGB(0xaf, 0xff, 0xff),  /* 159: PaleTurquoise1 */
+    QERGB(0xd7, 0x00, 0x00),  /* 160: Red3 */
+    QERGB(0xd7, 0x00, 0x5f),  /* 161: DeepPink3 */
+    QERGB(0xd7, 0x00, 0x87),  /* 162: DeepPink3 */
+    QERGB(0xd7, 0x00, 0xaf),  /* 163: Magenta3 */
+    QERGB(0xd7, 0x00, 0xd7),  /* 164: Magenta3 */
+    QERGB(0xd7, 0x00, 0xff),  /* 165: Magenta2 */
+    QERGB(0xd7, 0x5f, 0x00),  /* 166: DarkOrange3 */
+    QERGB(0xd7, 0x5f, 0x5f),  /* 167: IndianRed */
+    QERGB(0xd7, 0x5f, 0x87),  /* 168: HotPink3 */
+    QERGB(0xd7, 0x5f, 0xaf),  /* 169: HotPink2 */
+    QERGB(0xd7, 0x5f, 0xd7),  /* 170: Orchid */
+    QERGB(0xd7, 0x5f, 0xff),  /* 171: MediumOrchid1 */
+    QERGB(0xd7, 0x87, 0x00),  /* 172: Orange3 */
+    QERGB(0xd7, 0x87, 0x5f),  /* 173: LightSalmon3 */
+    QERGB(0xd7, 0x87, 0x87),  /* 174: LightPink3 */
+    QERGB(0xd7, 0x87, 0xaf),  /* 175: Pink3 */
+    QERGB(0xd7, 0x87, 0xd7),  /* 176: Plum3 */
+    QERGB(0xd7, 0x87, 0xff),  /* 177: Violet */
+    QERGB(0xd7, 0xaf, 0x00),  /* 178: Gold3 */
+    QERGB(0xd7, 0xaf, 0x5f),  /* 179: LightGoldenrod3 */
+    QERGB(0xd7, 0xaf, 0x87),  /* 180: Tan */
+    QERGB(0xd7, 0xaf, 0xaf),  /* 181: MistyRose3 */
+    QERGB(0xd7, 0xaf, 0xd7),  /* 182: Thistle3 */
+    QERGB(0xd7, 0xaf, 0xff),  /* 183: Plum2 */
+    QERGB(0xd7, 0xd7, 0x00),  /* 184: Yellow3 */
+    QERGB(0xd7, 0xd7, 0x5f),  /* 185: Khaki3 */
+    QERGB(0xd7, 0xd7, 0x87),  /* 186: LightGoldenrod2 */
+    QERGB(0xd7, 0xd7, 0xaf),  /* 187: LightYellow3 */
+    QERGB(0xd7, 0xd7, 0xd7),  /* 188: Grey84 */
+    QERGB(0xd7, 0xd7, 0xff),  /* 189: LightSteelBlue1 */
+    QERGB(0xd7, 0xff, 0x00),  /* 190: Yellow2 */
+    QERGB(0xd7, 0xff, 0x5f),  /* 191: DarkOliveGreen1 */
+    QERGB(0xd7, 0xff, 0x87),  /* 192: DarkOliveGreen1 */
+    QERGB(0xd7, 0xff, 0xaf),  /* 193: DarkSeaGreen1 */
+    QERGB(0xd7, 0xff, 0xd7),  /* 194: Honeydew2 */
+    QERGB(0xd7, 0xff, 0xff),  /* 195: LightCyan1 */
+    QERGB(0xff, 0x00, 0x00),  /* 196: Red1 */
+    QERGB(0xff, 0x00, 0x5f),  /* 197: DeepPink2 */
+    QERGB(0xff, 0x00, 0x87),  /* 198: DeepPink1 */
+    QERGB(0xff, 0x00, 0xaf),  /* 199: DeepPink1 */
+    QERGB(0xff, 0x00, 0xd7),  /* 200: Magenta2 */
+    QERGB(0xff, 0x00, 0xff),  /* 201: Magenta1 */
+    QERGB(0xff, 0x5f, 0x00),  /* 202: OrangeRed1 */
+    QERGB(0xff, 0x5f, 0x5f),  /* 203: IndianRed1 */
+    QERGB(0xff, 0x5f, 0x87),  /* 204: IndianRed1 */
+    QERGB(0xff, 0x5f, 0xaf),  /* 205: HotPink */
+    QERGB(0xff, 0x5f, 0xd7),  /* 206: HotPink */
+    QERGB(0xff, 0x5f, 0xff),  /* 207: MediumOrchid1 */
+    QERGB(0xff, 0x87, 0x00),  /* 208: DarkOrange */
+    QERGB(0xff, 0x87, 0x5f),  /* 209: Salmon1 */
+    QERGB(0xff, 0x87, 0x87),  /* 210: LightCoral */
+    QERGB(0xff, 0x87, 0xaf),  /* 211: PaleVioletRed1 */
+    QERGB(0xff, 0x87, 0xd7),  /* 212: Orchid2 */
+    QERGB(0xff, 0x87, 0xff),  /* 213: Orchid1 */
+    QERGB(0xff, 0xaf, 0x00),  /* 214: Orange1 */
+    QERGB(0xff, 0xaf, 0x5f),  /* 215: SandyBrown */
+    QERGB(0xff, 0xaf, 0x87),  /* 216: LightSalmon1 */
+    QERGB(0xff, 0xaf, 0xaf),  /* 217: LightPink1 */
+    QERGB(0xff, 0xaf, 0xd7),  /* 218: Pink1 */
+    QERGB(0xff, 0xaf, 0xff),  /* 219: Plum1 */
+    QERGB(0xff, 0xd7, 0x00),  /* 220: Gold1 */
+    QERGB(0xff, 0xd7, 0x5f),  /* 221: LightGoldenrod2 */
+    QERGB(0xff, 0xd7, 0x87),  /* 222: LightGoldenrod2 */
+    QERGB(0xff, 0xd7, 0xaf),  /* 223: NavajoWhite1 */
+    QERGB(0xff, 0xd7, 0xd7),  /* 224: MistyRose1 */
+    QERGB(0xff, 0xd7, 0xff),  /* 225: Thistle1 */
+    QERGB(0xff, 0xff, 0x00),  /* 226: Yellow1 */
+    QERGB(0xff, 0xff, 0x5f),  /* 227: LightGoldenrod1 */
+    QERGB(0xff, 0xff, 0x87),  /* 228: Khaki1 */
+    QERGB(0xff, 0xff, 0xaf),  /* 229: Wheat1 */
+    QERGB(0xff, 0xff, 0xd7),  /* 230: Cornsilk1 */
+    QERGB(0xff, 0xff, 0xff),  /* 231: Grey100 */
+    QERGB(0x08, 0x08, 0x08),  /* 232: Grey3 */
+    QERGB(0x12, 0x12, 0x12),  /* 233: Grey7 */
+    QERGB(0x1c, 0x1c, 0x1c),  /* 234: Grey11 */
+    QERGB(0x26, 0x26, 0x26),  /* 235: Grey15 */
+    QERGB(0x30, 0x30, 0x30),  /* 236: Grey19 */
+    QERGB(0x3a, 0x3a, 0x3a),  /* 237: Grey23 */
+    QERGB(0x44, 0x44, 0x44),  /* 238: Grey27 */
+    QERGB(0x4e, 0x4e, 0x4e),  /* 239: Grey30 */
+    QERGB(0x58, 0x58, 0x58),  /* 240: Grey35 */
+    QERGB(0x62, 0x62, 0x62),  /* 241: Grey39 */
+    QERGB(0x6c, 0x6c, 0x6c),  /* 242: Grey42 */
+    QERGB(0x76, 0x76, 0x76),  /* 243: Grey46 */
+    QERGB(0x80, 0x80, 0x80),  /* 244: Grey50 */
+    QERGB(0x8a, 0x8a, 0x8a),  /* 245: Grey54 */
+    QERGB(0x94, 0x94, 0x94),  /* 246: Grey58 */
+    QERGB(0x9e, 0x9e, 0x9e),  /* 247: Grey62 */
+    QERGB(0xa8, 0xa8, 0xa8),  /* 248: Grey66 */
+    QERGB(0xb2, 0xb2, 0xb2),  /* 249: Grey70 */
+    QERGB(0xbc, 0xbc, 0xbc),  /* 250: Grey74 */
+    QERGB(0xc6, 0xc6, 0xc6),  /* 251: Grey78 */
+    QERGB(0xd0, 0xd0, 0xd0),  /* 252: Grey82 */
+    QERGB(0xda, 0xda, 0xda),  /* 253: Grey85 */
+    QERGB(0xe4, 0xe4, 0xe4),  /* 254: Grey89 */
+    QERGB(0xee, 0xee, 0xee),  /* 255: Grey93 */
+#endif
 };
 
-static int get_tty_color(QEColor color, unsigned int const *colors, int count)
+unsigned int const *tty_bg_colors = tty_putty_colors;
+unsigned int const *tty_fg_colors = tty_putty_colors;
+int tty_bg_colors_count = 16;
+int tty_fg_colors_count = 16;
+
+static inline int color_dist(unsigned int c1, unsigned c2)
+{
+
+    return (abs( (c1 & 0xff) - (c2 & 0xff)) +
+            2 * abs( ((c1 >> 8) & 0xff) - ((c2 >> 8) & 0xff)) +
+            abs( ((c1 >> 16) & 0xff) - ((c2 >> 16) & 0xff)));
+}
+
+int get_tty_color(QEColor color, unsigned int const *colors, int count)
 {
     int i, cmin, dmin, d;
 
@@ -582,7 +839,7 @@
             ptr += wrap;
         }
     } else {
-        bgcolor = get_tty_color(color, tty_bg_colors, countof(tty_bg_colors));
+        bgcolor = get_tty_color(color, tty_bg_colors, tty_bg_colors_count);
         for (y = y1; y < y2; y++) {
             ts->line_updated[y] = 1;
             for (x = x1; x < x2; x++) {
@@ -704,7 +961,7 @@
         return;
 
     ts->line_updated[y] = 1;
-    fgcolor = get_tty_color(color, tty_fg_colors, countof(tty_fg_colors));
+    fgcolor = get_tty_color(color, tty_fg_colors, tty_fg_colors_count);
     ptr = ts->screen + y * s->width;
 
     if (x < s->clip_x1) {
@@ -840,15 +1097,26 @@
                 if (ch != 0xffff) {
                     /* output attributes */
                     if (bgcolor != (int)TTYCHAR_GETBG(cc)) {
+                        /* should use array of strings */
                         bgcolor = TTYCHAR_GETBG(cc);
-                        TTY_FPRINTF(s->STDOUT, "\033[%dm", 40 + bgcolor);
+                        TTY_FPRINTF(s->STDOUT, "\033[%dm",
+                                    bgcolor >= 8 ? 100 + bgcolor - 8 :
+                                    40 + bgcolor);
                     }
                     if (fgcolor != (int)TTYCHAR_GETFG(cc) && ch != ' ') {
                         fgcolor = TTYCHAR_GETFG(cc);
+                        /* should use array of strings */
+                        if (0) {
+                            /* use bold for high color */
                         TTY_FPRINTF(s->STDOUT, "\033[%dm",
                                     (fgcolor > 7) ? 1 : 22);
                         TTY_FPRINTF(s->STDOUT, "\033[%dm",
                                     30 + (fgcolor & 7));
+                        } else {
+                            TTY_FPRINTF(s->STDOUT, "\033[%dm",
+                                        fgcolor >= 8 ? 90 + fgcolor - 8 :
+                                        30 + fgcolor);
+                        }
                     }
                     if (shifted) {
                         /* Kludge for linedrawing chars */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]