irssi-import / bugs.irssi.org

bugs.irssi.org archive
https://github.com/irssi/irssi/issues
0 stars 0 forks source link

Support for mIRC's italics control code #793

Open irssibot opened 13 years ago

irssibot commented 13 years ago

http://inari.aerdan.org/irssi-italics.patch adds support for mIRC 7's addition of ^] (chr(29)) to the controlcode roster, implemented as underlining (for now). It additionally adds / as an emphasis character behind a default-off flag called emphasis_underline_slashes (could probably be better named).

irssibot commented 11 years ago

Supports true italics for terminals that do. Adds "%I" and "/italicize/".

To see if you have a terminal that can handle it:

echo "$(tput sitm)this should be italicized$(tput ritm)"

For me it works with urxvt inside tmux I needed the TERM fix from here http://sourceforge.net/p/tmux/tmux-code/ci/master/tree/FAQ

irssibot commented 11 years ago

irssi-italics.diff

Index: src/fe-common/core/fe-messages.c
===================================================================
--- src/fe-common/core/fe-messages.c    (revision 5217)
+++ src/fe-common/core/fe-messages.c    (working copy)
@@ -45,8 +45,8 @@

 GHashTable *printnicks;

-/* convert _underlined_ and *bold* words (and phrases) to use real
-   underlining or bolding */
+/* convert _underlined_, *bold* and /italic/ words (and phrases) to use real
+   underlining, bolding or italics*/
 char *expand_emphasis(WI_ITEM_REC *item, const char *text)
 {
    GString *str;
@@ -64,8 +64,10 @@

        if (*bgn == '*') 
            type = 2; /* bold */
-       else if (*bgn == '_') 
+       else if (*bgn == '_')
            type = 31; /* underlined */
+       else if (settings_get_bool("italics") &&(*bgn == '/'))
+           type = 29; /* italics */
        else
            continue;

@@ -76,7 +78,8 @@
        if ((end = strchr(bgn+1, *bgn)) == NULL)
            continue;
        if (!ishighalnum(end[-1]) || ishighalnum(end[1]) ||
-           end[1] == type || end[1] == '*' || end[1] == '_')
+           end[1] == type || end[1] == '*' || end[1] == '_' ||
+           end[1] == '/')
            continue;

        if (IS_CHANNEL(item)) {
@@ -640,6 +643,10 @@
                      (GCompareFunc) g_direct_equal);

    settings_add_bool("lookandfeel", "hilight_nick_matches", TRUE);
+    /* Allows for "%Iitalics" and given 'emphasis' also /italics/
+     * disabled by default due to lack of (and sometimes
+     * broken) terminal support */
+   settings_add_bool("lookandfeel", "italics", FALSE); 
    settings_add_bool("lookandfeel", "emphasis", TRUE);
    settings_add_bool("lookandfeel", "emphasis_replace", FALSE);
    settings_add_bool("lookandfeel", "emphasis_multiword", FALSE);
Index: src/fe-common/core/formats.c
===================================================================
--- src/fe-common/core/formats.c    (revision 5217)
+++ src/fe-common/core/formats.c    (working copy)
@@ -138,6 +138,13 @@
        g_string_append_c(out, 4);
        g_string_append_c(out, FORMAT_STYLE_INDENT);
        break;
+   case 'I':
+       /* italics on/off */
+       if (settings_get_bool("italics")){
+           g_string_append_c(out, 4);
+           g_string_append_c(out, FORMAT_STYLE_ITALICS);
+       }
+       break;
    case 'F':
        /* blink */
        g_string_append_c(out, 4);
@@ -755,6 +762,10 @@
            /* hilight */
            flags |= GUI_PRINT_FLAG_BOLD;
            break;
+       case 3:
+           /* italics */
+           flags |= GUI_PRINT_FLAG_ITALICS;
+           break;
        case 5:
            /* blink */
            flags |= GUI_PRINT_FLAG_BLINK;
@@ -832,7 +843,7 @@

 #define IS_COLOR_CODE(c) \
    ((c) == 2 || (c) == 3 || (c) == 4 || (c) == 6 || (c) == 7 || \
-   (c) == 15 || (c) == 22 || (c) == 27 || (c) == 31)
+   (c) == 15 || (c) == 22 || (c) == 27 || (c) == 29 || (c) == 31)

 /* Return how many characters in `str' must be skipped before `len'
    characters of text is skipped. */
@@ -1001,6 +1012,9 @@
            case FORMAT_STYLE_UNDERLINE:
                flags ^= GUI_PRINT_FLAG_UNDERLINE;
                break;
+           case FORMAT_STYLE_ITALICS:
+               flags ^= GUI_PRINT_FLAG_ITALICS;
+               break;
            case FORMAT_STYLE_BOLD:
                flags ^= GUI_PRINT_FLAG_BOLD;
                break;
@@ -1050,6 +1064,11 @@
            if (!hide_text_style)
                flags ^= GUI_PRINT_FLAG_REVERSE;
            break;
+       case 29:
+           /* italics */
+           if (!hide_text_style)
+               flags ^= GUI_PRINT_FLAG_ITALICS;
+           break;
        case 31:
            /* underline */
            if (!hide_text_style)
Index: src/fe-common/core/formats.h
===================================================================
--- src/fe-common/core/formats.h    (revision 5217)
+++ src/fe-common/core/formats.h    (working copy)
@@ -7,9 +7,10 @@
 #define GUI_PRINT_FLAG_BOLD          0x0001
 #define GUI_PRINT_FLAG_REVERSE       0x0002
 #define GUI_PRINT_FLAG_UNDERLINE     0x0004
-#define GUI_PRINT_FLAG_BLINK         0x0008
-#define GUI_PRINT_FLAG_MIRC_COLOR    0x0010
-#define GUI_PRINT_FLAG_INDENT        0x0020
+#define GUI_PRINT_FLAG_ITALICS       0x0008
+#define GUI_PRINT_FLAG_BLINK         0x0010
+#define GUI_PRINT_FLAG_MIRC_COLOR    0x0020
+#define GUI_PRINT_FLAG_INDENT        0x0040
 #define GUI_PRINT_FLAG_NEWLINE       0x0080
 #define GUI_PRINT_FLAG_CLRTOEOL      0x0100
 #define GUI_PRINT_FLAG_MONOSPACE     0x0200
@@ -126,8 +127,9 @@
 #define FORMAT_STYLE_BLINK (0x01 + FORMAT_STYLE_SPECIAL)
 #define FORMAT_STYLE_UNDERLINE (0x02 + FORMAT_STYLE_SPECIAL)
 #define FORMAT_STYLE_BOLD  (0x03 + FORMAT_STYLE_SPECIAL)
-#define FORMAT_STYLE_REVERSE   (0x04 + FORMAT_STYLE_SPECIAL)
-#define FORMAT_STYLE_INDENT    (0x05 + FORMAT_STYLE_SPECIAL)
+#define FORMAT_STYLE_ITALICS   (0x04 + FORMAT_STYLE_SPECIAL)
+#define FORMAT_STYLE_REVERSE   (0x05 + FORMAT_STYLE_SPECIAL)
+#define FORMAT_STYLE_INDENT    (0x06 + FORMAT_STYLE_SPECIAL)
 #define FORMAT_STYLE_DEFAULTS  (0x07 + FORMAT_STYLE_SPECIAL)
 #define FORMAT_STYLE_CLRTOEOL  (0x08 + FORMAT_STYLE_SPECIAL)
 #define FORMAT_STYLE_MONOSPACE (0x09 + FORMAT_STYLE_SPECIAL)
Index: src/fe-text/gui-printtext.c
===================================================================
--- src/fe-text/gui-printtext.c (revision 5217)
+++ src/fe-text/gui-printtext.c (working copy)
@@ -157,6 +157,7 @@
    if (flags & GUI_PRINT_FLAG_REVERSE) *attr |= ATTR_REVERSE;
    if (flags & GUI_PRINT_FLAG_BOLD) *attr |= ATTR_BOLD;
    if (flags & GUI_PRINT_FLAG_UNDERLINE) *attr |= ATTR_UNDERLINE;
+   if (settings_get_bool("italics") && (flags & GUI_PRINT_FLAG_ITALICS)) *attr |= ATTR_ITALICS;
    if (flags & GUI_PRINT_FLAG_BLINK) *attr |= ATTR_BLINK;
 }

Index: src/fe-text/term-curses.c
===================================================================
--- src/fe-text/term-curses.c   (revision 5217)
+++ src/fe-text/term-curses.c   (working copy)
@@ -291,6 +291,8 @@

    if ((color & 0x08) || (color & ATTR_BOLD)) attr |= A_BOLD;
    if (color & ATTR_BLINK) attr |= A_BLINK;
+   //A_ALTCHARSET a good cohice?
+   if (color & ATTR_ITALICS) attr |= A_ALTCHARSET;

    if (color & ATTR_UNDERLINE) attr |= A_UNDERLINE;
    if (color & ATTR_REVERSE) attr |= A_REVERSE;
Index: src/fe-text/term-terminfo.c
===================================================================
--- src/fe-text/term-terminfo.c (revision 5217)
+++ src/fe-text/term-terminfo.c (working copy)
@@ -300,10 +300,11 @@
    int fg = col & 0x0f;
    int bg = (col & 0xf0) >> 4;

-        set_normal = ((col & ATTR_RESETFG) && last_fg != -1) ||
+   set_normal = ((col & ATTR_RESETFG) && last_fg != -1) ||
        ((col & ATTR_RESETBG) && last_bg != -1);
-   if (((last_attrs & ATTR_BOLD) && (col & ATTR_BOLD) == 0) ||
-       ((last_attrs & ATTR_BLINK) && (col & ATTR_BLINK) == 0)) {
+    if (((last_attrs & ATTR_BOLD) && (col & ATTR_BOLD) == 0) ||
+       ((last_attrs & ATTR_BLINK) && (col & ATTR_BLINK) == 0) ||
+       ((last_attrs & ATTR_ITALICS) && (col & ATTR_ITALICS) == 0)) {
        /* we'll need to get rid of bold/blink - this can only be
           done with setting the default color */
        set_normal = TRUE;
@@ -342,7 +343,7 @@

    if (bg != last_bg &&
        (bg != 0 || (col & ATTR_RESETBG) == 0)) {
-                if (term_use_colors) {
+       if (term_use_colors) {
            last_bg = bg;
            terminfo_set_bg(last_bg);
        }
@@ -354,6 +355,14 @@
    if (col & ATTR_BOLD)
        terminfo_set_bold();

+   /* italics */
+   if (col & ATTR_ITALICS){
+       if ((last_attrs & ATTR_ITALICS) == 0)
+           terminfo_set_italics(TRUE);
+   } else if (last_attrs & ATTR_ITALICS)
+       terminfo_set_italics(FALSE);
+
+
    /* underline */
    if (col & ATTR_UNDERLINE) {
        if ((last_attrs & ATTR_UNDERLINE) == 0)
@@ -361,7 +370,7 @@
    } else if (last_attrs & ATTR_UNDERLINE)
        terminfo_set_uline(FALSE);

-        last_attrs = col & ~0xff;
+   last_attrs = col & ~0xff;
 }

 void term_move(TERM_WINDOW *window, int x, int y)
Index: src/fe-text/term.h
===================================================================
--- src/fe-text/term.h  (revision 5217)
+++ src/fe-text/term.h  (working copy)
@@ -10,10 +10,11 @@
 #define ATTR_BLINK      0x0800
 #define ATTR_UNDERLINE 0x1000
 #define ATTR_REVERSE   0x2000
+#define ATTR_ITALICS   0x4000

 #define ATTR_RESET (ATTR_RESETFG|ATTR_RESETBG)

-#define ATTR_NOCOLORS (ATTR_UNDERLINE|ATTR_REVERSE|ATTR_BLINK|ATTR_BOLD)
+#define ATTR_NOCOLORS (ATTR_UNDERLINE|ATTR_REVERSE|ATTR_BLINK|ATTR_BOLD|ATTR_ITALICS)

 /* terminal types */
 #define TERM_TYPE_8BIT     0 /* normal 8bit text */
Index: src/fe-text/terminfo-core.c
===================================================================
--- src/fe-text/terminfo-core.c (revision 5217)
+++ src/fe-text/terminfo-core.c (working copy)
@@ -92,6 +92,8 @@
    { "sgr0",       "me",   CAP_TYPE_STR,   G_STRUCT_OFFSET(TERM_REC, TI_sgr0) },
    { "smul",       "us",   CAP_TYPE_STR,   G_STRUCT_OFFSET(TERM_REC, TI_smul) },
    { "rmul",       "ue",   CAP_TYPE_STR,   G_STRUCT_OFFSET(TERM_REC, TI_rmul) },
+   { "sitm",       "ZH",   CAP_TYPE_STR,   G_STRUCT_OFFSET(TERM_REC, TI_sitm) },
+   { "ritm",       "ZR",   CAP_TYPE_STR,   G_STRUCT_OFFSET(TERM_REC, TI_ritm) },
    { "smso",       "so",   CAP_TYPE_STR,   G_STRUCT_OFFSET(TERM_REC, TI_smso) },
    { "rmso",       "se",   CAP_TYPE_STR,   G_STRUCT_OFFSET(TERM_REC, TI_rmso) },
    { "bold",       "md",   CAP_TYPE_STR,   G_STRUCT_OFFSET(TERM_REC, TI_bold) },
@@ -325,6 +327,12 @@
    tput(tparm(set ? term->TI_smul : term->TI_rmul));
 }

+/* Italics on/off */
+static void _set_italics(TERM_REC *term, int set)
+{
+   tput(tparm(set ? term->TI_sitm : term->TI_ritm));
+}
+
 /* Standout on/off */
 static void _set_standout(TERM_REC *term, int set)
 {
@@ -596,13 +604,15 @@
    else
        term->repeat = _repeat_manual;

-   /* Bold, underline, standout */
+   /* Bold, underline, standout, italics */
    term->set_blink = term->TI_blink ? _set_blink : _ignore;
    term->set_bold = term->TI_bold ? _set_bold : _ignore;
    term->set_uline = term->TI_smul && term->TI_rmul ?
        _set_uline : _ignore_parm;
    term->set_standout = term->TI_smso && term->TI_rmso ?
        _set_standout : _ignore_parm;
+   term->set_italics = term->TI_sitm && term->TI_ritm ?
+       _set_italics : _ignore_parm;

         /* Create a string to set all attributes off */
         str = g_string_new(NULL);
@@ -610,6 +620,8 @@
        g_string_append(str, term->TI_sgr0);
    if (term->TI_rmul && (term->TI_sgr0 == NULL || strcmp(term->TI_rmul, term->TI_sgr0) != 0))
        g_string_append(str, term->TI_rmul);
+   if (term->TI_ritm && (term->TI_sgr0 == NULL || strcmp(term->TI_ritm, term->TI_sgr0) != 0))
+       g_string_append(str, term->TI_ritm);
    if (term->TI_rmso && (term->TI_sgr0 == NULL || strcmp(term->TI_rmso, term->TI_sgr0) != 0))
        g_string_append(str, term->TI_rmso);
         term->TI_normal = str->str;
Index: src/fe-text/terminfo-core.h
===================================================================
--- src/fe-text/terminfo-core.h (revision 5217)
+++ src/fe-text/terminfo-core.h (working copy)
@@ -14,6 +14,7 @@
 #define terminfo_set_bg(color) current_term->set_bg(current_term, color)
 #define terminfo_set_normal() current_term->set_normal(current_term)
 #define terminfo_set_bold() current_term->set_bold(current_term)
+#define terminfo_set_italics(set) current_term->set_italics(current_term, set)
 #define terminfo_set_uline(set) current_term->set_uline(current_term, set)
 #define terminfo_set_standout(set) current_term->set_standout(current_term, set)
 #define terminfo_is_colors_set(term) (term->TI_fg != NULL)
@@ -37,10 +38,11 @@
    void (*set_normal)(TERM_REC *term);
    void (*set_blink)(TERM_REC *term);
    void (*set_bold)(TERM_REC *term);
+   void (*set_italics)(TERM_REC *term, int set);
    void (*set_uline)(TERM_REC *term, int set);
    void (*set_standout)(TERM_REC *term, int set);

-        void (*beep)(TERM_REC *term);
+   void (*beep)(TERM_REC *term);

 #ifndef HAVE_TERMINFO
    char buffer1[1024], buffer2[1024];
@@ -74,11 +76,12 @@
    int TI_colors; /* numbers of colors in TI_fg[] and TI_bg[] */
    const char *TI_sgr0; /* turn off all attributes */
    const char *TI_smul, *TI_rmul; /* underline on/off */
-        const char *TI_smso, *TI_rmso; /* standout on/off */
-        const char *TI_bold, *TI_blink;
+   const char *TI_smso, *TI_rmso; /* standout on/off */
+   const char *TI_sitm, *TI_ritm; /* italics on/off */
+   const char *TI_bold, *TI_blink;
    const char *TI_setaf, *TI_setab, *TI_setf, *TI_setb;

-        /* Colors - generated and dynamically allocated */
+   /* Colors - generated and dynamically allocated */
    char **TI_fg, **TI_bg, *TI_normal;

    /* Beep */
Index: src/fe-text/textbuffer-view.c
===================================================================
--- src/fe-text/textbuffer-view.c   (revision 5217)
+++ src/fe-text/textbuffer-view.c   (working copy)
@@ -140,6 +140,9 @@
    case LINE_CMD_BOLD:
        *color ^= ATTR_BOLD;
        break;
+   case LINE_CMD_ITALICS:
+       *color ^= ATTR_ITALICS;
+       break;
    case LINE_CMD_COLOR0:
        *color &= BGATTR;
        break;
Index: src/fe-text/textbuffer.c
===================================================================
--- src/fe-text/textbuffer.c    (revision 5217)
+++ src/fe-text/textbuffer.c    (working copy)
@@ -264,6 +264,10 @@
        data[pos++] = 0;
        data[pos++] = LINE_CMD_BOLD;
    }
+   if ((flags & GUI_PRINT_FLAG_ITALICS) != (buffer->last_flags & GUI_PRINT_FLAG_ITALICS)){
+       data[pos++] = 0;
+       data[pos++] = LINE_CMD_ITALICS;
+   }
    if (flags & GUI_PRINT_FLAG_INDENT) {
        data[pos++] = 0;
        data[pos++] = LINE_CMD_INDENT;
@@ -436,6 +440,10 @@
            g_string_append_printf(str, "\004%c",
                      FORMAT_STYLE_BOLD);
            break;
+       case LINE_CMD_ITALICS:
+           g_string_append_printf(str, "\004%c",
+                     FORMAT_STYLE_ITALICS);
+           break;
        case LINE_CMD_COLOR0:
            g_string_append_printf(str, "\004%c%c",
                      '0', FORMAT_COLOR_NOCHANGE);
Index: src/fe-text/textbuffer.h
===================================================================
--- src/fe-text/textbuffer.h    (revision 5217)
+++ src/fe-text/textbuffer.h    (working copy)
@@ -17,6 +17,7 @@
    LINE_CMD_INDENT,    /* if line is split, indent it at this position */
    LINE_CMD_BLINK,     /* enable/disable blink */
    LINE_CMD_BOLD,      /* enable/disable bold */
+   LINE_CMD_ITALICS,   /* enable/disable italics */
 };

 typedef struct {