On 2/5/2012 5:55 PM, Peter Lustig wrote:
On 2/4/2012 9:56 PM, Peter Lustig wrote:
On 1/22/2012 3:44 AM, Nicholas Marriott wrote:
IIRC I sent some comments and heard nothing more.


On Sat, Jan 21, 2012 at 10:50:04PM -0500, Peter Lustig wrote:
Sorry to resurrect an old thread.

Does anyone know what became of this patch? I found no more discussion
of it after this thread, and see no traces of it in the trunk.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users
I'd like to pick up where Stephen Prater left off on this effort. Here is a patch to "tty.c" that resolves the original problem while incorporating the recommendations you made back then. Let me know if there are any issues with it, and I'll be glad to fix them.
My bad. Just found a bug in the patch I submitted: on line 156 'GRID_FLAG_FG256' should be 'GRID_FLAG_BG256'. Here is the fixed version.
Here's another iteration of the patch to improve support for aixterm (SGR 90-97 and 100-107) colours. The old behavior of 'down-converting' the colours to their ANSI equivalents (with the bold bit set) has been kept for 8-colour terminals. However, for 256/88-colour terminals, the colours are now translated to their direct xterm-256-colour analogues (e.g. '\e[91m' maps to '\e[38;5;8m', with TERM='screen-256color'). Only 16-colour terminals now receive the colours unaltered.

I'm aware this fix might be better implemented in 'input.c'. What do you think? Does this seem the best approach? Or is there a compelling reason to pass the aixterm colours unaltered to 256/88-colour terminals, other than to save a few characters?
--- tty.c.0     2012-01-29 18:38:30.591868756 -0500
+++ tty.c       2012-02-08 22:24:44.689771476 -0500
@@ -30,17 +30,14 @@
 #include <unistd.h>
 
 #include "tmux.h"
 
 void   tty_read_callback(struct bufferevent *, void *);
 void   tty_error_callback(struct bufferevent *, short, void *);
 
-int    tty_try_256(struct tty *, u_char, const char *);
-int    tty_try_88(struct tty *, u_char, const char *);
-
 void   tty_colours(struct tty *, const struct grid_cell *);
 void   tty_check_fg(struct tty *, struct grid_cell *);
 void   tty_check_bg(struct tty *, struct grid_cell *);
 void   tty_colours_fg(struct tty *, const struct grid_cell *);
 void   tty_colours_bg(struct tty *, const struct grid_cell *);
 
 void   tty_redraw_region(struct tty *, const struct tty_ctx *);
@@ -1390,173 +1387,136 @@
 void
 tty_check_fg(struct tty *tty, struct grid_cell *gc)
 {
        u_int   colours;
 
        /* Is this a 256-colour colour? */
        if (gc->flags & GRID_FLAG_FG256) {
-               /* And not a 256 colour mode? */
-               if (!(tty->term->flags & TERM_88COLOURS) &&
-                   !(tty->term_flags & TERM_88COLOURS) &&
-                   !(tty->term->flags & TERM_256COLOURS) &&
-                   !(tty->term_flags & TERM_256COLOURS)) {
+               /* And an 88-colour mode? */
+               if ((tty->term->flags & TERM_88COLOURS) ||
+                   (tty->term_flags & TERM_88COLOURS)) {
+                       gc->fg = colour_256to88(gc->fg);
+               /* Or a 16-colour mode? */
+               } else if (!(tty->term->flags & TERM_256COLOURS) &&
+                          !(tty->term_flags & TERM_256COLOURS)) {
                        gc->fg = colour_256to16(gc->fg);
                        if (gc->fg & 8) {
                                gc->fg &= 7;
                                gc->attr |= GRID_ATTR_BRIGHT;
                        } else
                                gc->attr &= ~GRID_ATTR_BRIGHT;
                        gc->flags &= ~GRID_FLAG_FG256;
                }
                return;
        }
 
-       /* Is this an aixterm colour? */
-       colours = tty_term_number(tty->term, TTYC_COLORS);
-       if (gc->fg >= 90 && gc->fg <= 97 && colours < 16) {
-               gc->fg -= 90;
-               gc->attr |= GRID_ATTR_BRIGHT;
+       /* Else, is this an aixterm colour? */
+       if (gc->fg >= 90 && gc->fg <= 97) {
+               colours = tty_term_number(tty->term, TTYC_COLORS);
+
+               /* And a 256/88-colour mode? */
+               if (colours > 16) {
+                       gc->fg -= 82;
+                       gc->flags |= GRID_FLAG_FG256;
+               /* Or an 8-colour mode? */
+               } else if (colours < 16) {
+                       gc->fg -= 90;
+                       gc->attr |= GRID_ATTR_BRIGHT;
+               }
        }
 }
 
 void
 tty_check_bg(struct tty *tty, struct grid_cell *gc)
 {
        u_int   colours;
 
        /* Is this a 256-colour colour? */
        if (gc->flags & GRID_FLAG_BG256) {
-               /*
-                * And not a 256 colour mode? Translate to 16-colour
+               /* And an 88-colour mode? */
+               if ((tty->term->flags & TERM_88COLOURS) ||
+                   (tty->term_flags & TERM_88COLOURS)) {
+                       gc->bg = colour_256to88(gc->bg);
+               /* Or a 16-colour mode? Translate to 16-colour
                 * palette. Bold background doesn't exist portably, so just
                 * discard the bold bit if set.
                 */
-               if (!(tty->term->flags & TERM_88COLOURS) &&
-                   !(tty->term_flags & TERM_88COLOURS) &&
-                   !(tty->term->flags & TERM_256COLOURS) &&
-                   !(tty->term_flags & TERM_256COLOURS)) {
+               } else if (!(tty->term->flags & TERM_256COLOURS) &&
+                          !(tty->term_flags & TERM_256COLOURS)) {
                        gc->bg = colour_256to16(gc->bg);
                        if (gc->bg & 8)
                                gc->bg &= 7;
                        gc->attr &= ~GRID_ATTR_BRIGHT;
                        gc->flags &= ~GRID_FLAG_BG256;
                }
                return;
        }
 
-       /* Is this an aixterm colour? */
-       colours = tty_term_number(tty->term, TTYC_COLORS);
-       if (gc->bg >= 90 && gc->bg <= 97 && colours < 16) {
-               gc->bg -= 90;
-               gc->attr |= GRID_ATTR_BRIGHT;
+       /* Else, is this an aixterm colour? */
+       if (gc->bg >= 90 && gc->bg <= 97) {
+               colours = tty_term_number(tty->term, TTYC_COLORS);
+
+               /* And a 256/88-colour mode? */
+               if (colours > 16) {
+                       gc->bg -= 82;
+                       gc->flags |= GRID_FLAG_BG256;
+               /* Or an 8-colour mode? */
+               } else if (colours < 16) {
+                       gc->bg -= 90;
+                       gc->attr |= GRID_ATTR_BRIGHT;
+               }
        }
 }
 
 void
 tty_colours_fg(struct tty *tty, const struct grid_cell *gc)
 {
        struct grid_cell        *tc = &tty->cell;
        u_char                   fg = gc->fg;
        char                     s[32];
 
-       /* Is this a 256-colour colour? */
-       if (gc->flags & GRID_FLAG_FG256) {
-               /* Try as 256 colours or translating to 88. */
-               if (tty_try_256(tty, fg, "38") == 0)
-                       goto save_fg;
-               if (tty_try_88(tty, fg, "38") == 0)
-                       goto save_fg;
-               /* Else already handled by tty_check_fg. */
-               return;
-       }
-
        /* Is this an aixterm bright colour? */
-       if (fg >= 90 && fg <= 97) {
+       if (!(gc->flags & GRID_FLAG_FG256) &&
+            (fg >= 90 && fg <= 97)) {
                xsnprintf(s, sizeof s, "\033[%dm", fg);
                tty_puts(tty, s);
-               goto save_fg;
-       }
-
        /* Otherwise set the foreground colour. */
-       tty_putcode1(tty, TTYC_SETAF, fg);
+       } else
+               tty_putcode1(tty, TTYC_SETAF, fg);
 
-save_fg:
        /* Save the new values in the terminal current cell. */
        tc->fg = fg;
        tc->flags &= ~GRID_FLAG_FG256;
        tc->flags |= gc->flags & GRID_FLAG_FG256;
 }
 
 void
 tty_colours_bg(struct tty *tty, const struct grid_cell *gc)
 {
        struct grid_cell        *tc = &tty->cell;
        u_char                   bg = gc->bg;
        char                     s[32];
 
-       /* Is this a 256-colour colour? */
-       if (gc->flags & GRID_FLAG_BG256) {
-               /* Try as 256 colours or translating to 88. */
-               if (tty_try_256(tty, bg, "48") == 0)
-                       goto save_bg;
-               if (tty_try_88(tty, bg, "48") == 0)
-                       goto save_bg;
-               /* Else already handled by tty_check_bg. */
-               return;
-       }
-
        /* Is this an aixterm bright colour? */
-       if (bg >= 90 && bg <= 97) {
+       if (!(gc->flags & GRID_FLAG_BG256) &&
+            (bg >= 90 && bg <= 97)) {
                /* 16 colour terminals or above only. */
                if (tty_term_number(tty->term, TTYC_COLORS) >= 16) {
                        xsnprintf(s, sizeof s, "\033[%dm", bg + 10);
                        tty_puts(tty, s);
-                       goto save_bg;
-               }
-               bg -= 90;
-               /* no such thing as a bold background */
-       }
-
+               } else 
+                       bg -= 90; /* no such thing as a bold background */
        /* Otherwise set the background colour. */
-       tty_putcode1(tty, TTYC_SETAB, bg);
+       } else
+               tty_putcode1(tty, TTYC_SETAB, bg);
 
-save_bg:
        /* Save the new values in the terminal current cell. */
        tc->bg = bg;
        tc->flags &= ~GRID_FLAG_BG256;
        tc->flags |= gc->flags & GRID_FLAG_BG256;
 }
 
-int
-tty_try_256(struct tty *tty, u_char colour, const char *type)
-{
-       char    s[32];
-
-       if (!(tty->term->flags & TERM_256COLOURS) &&
-           !(tty->term_flags & TERM_256COLOURS))
-               return (-1);
-
-       xsnprintf(s, sizeof s, "\033[%s;5;%hhum", type, colour);
-       tty_puts(tty, s);
-       return (0);
-}
-
-int
-tty_try_88(struct tty *tty, u_char colour, const char *type)
-{
-       char    s[32];
-
-       if (!(tty->term->flags & TERM_88COLOURS) &&
-           !(tty->term_flags & TERM_88COLOURS))
-               return (-1);
-       colour = colour_256to88(colour);
-
-       xsnprintf(s, sizeof s, "\033[%s;5;%hhum", type, colour);
-       tty_puts(tty, s);
-       return (0);
-}
-
 void
 tty_bell(struct tty *tty)
 {
        tty_putcode(tty, TTYC_BEL);
 }
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to