[hackers] [st] Implementing line drawing right. || Christoph Lohmann

From: <hg_AT_suckless.org>
Date: Wed, 26 Sep 2012 20:24:24 +0200 (CEST)

changeset: 335:16dd560aa117
user: Christoph Lohmann <20h_AT_r-36.net>
date: Wed Sep 26 20:21:08 2012 +0200
files: config.def.h st.c
description:
Implementing line drawing right.


diff -r 36f8cd105d65 -r 16dd560aa117 config.def.h
--- a/config.def.h Tue Sep 25 21:39:25 2012 +0200
+++ b/config.def.h Wed Sep 26 20:21:08 2012 +0200
_AT_@ -79,14 +79,6 @@
 /* Set TERM to this */
 #define TNAME "st-256color"
 
-/* Line drawing characters (sometime specific to each font...) */
-static char gfx[] = {
- ['f'] = 'o',
- ['g'] = '+',
- ['i'] = '#',
- [255] = 0,
-};
-
 /* double-click timeout (in milliseconds) between clicks for selection */
 #define DOUBLECLICK_TIMEOUT 300
 #define TRIPLECLICK_TIMEOUT (2*DOUBLECLICK_TIMEOUT)
diff -r 36f8cd105d65 -r 16dd560aa117 st.c
--- a/st.c Tue Sep 25 21:39:25 2012 +0200
+++ b/st.c Wed Sep 26 20:21:08 2012 +0200
_AT_@ -1094,6 +1094,27 @@
 
 void
 tsetchar(char *c) {
+ /*
+ * The table is proudly stolen from rxvt.
+ */
+ if(term.c.attr.mode & ATTR_GFX) {
+ char *vt100_0[62] = { /* 0x41 - 0x7e */
+ "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* P - W */
+ 0, 0, 0, 0, 0, 0, 0, " ", /* X - _ */
+ "◆", "▒", "␉", "␌", "␍", "␊", "°", "±", /* ` - g */
+ "␤", "␋", "┘", "┐", "┌", "└", "┼", "⎺", /* h - o */
+ "⎻", "─", "⎼", "⎽", "├", "┤", "┴", "┬", /* p - w */
+ "│", "≤", "≥", "π", "≠", "£", "·", /* x - ~ */
+ };
+
+ if(c[0] >= 0x41 && c[0] <= 0x7e
+ && vt100_0[c[0] - 0x41]) {
+ c = vt100_0[c[0] - 0x41];
+ }
+ }
+
         term.dirty[term.c.y] = 1;
         term.line[term.c.y][term.c.x] = term.c.attr;
         memcpy(term.line[term.c.y][term.c.x].c, c, UTF_SIZ);
_AT_@ -1177,7 +1198,7 @@
                 switch(attr[i]) {
                 case 0:
                         term.c.attr.mode &= ~(ATTR_REVERSE | ATTR_UNDERLINE | ATTR_BOLD \
- | ATTR_ITALIC | ATTR_BLINK | ATTR_GFX);
+ | ATTR_ITALIC | ATTR_BLINK);
                         term.c.attr.fg = DefaultFG;
                         term.c.attr.bg = DefaultBG;
                         break;
_AT_@ -1676,12 +1697,18 @@
                                 strhandle();
                 } else if(term.esc & ESC_ALTCHARSET) {
                         switch(ascii) {
- case '0': /* Line drawing crap */
+ case '0': /* Line drawing set */
                                 term.c.attr.mode |= ATTR_GFX;
                                 break;
- case 'B': /* Back to regular text */
+ case 'B': /* USASCII */
                                 term.c.attr.mode &= ~ATTR_GFX;
                                 break;
+ case 'A': /* UK (IGNORED) */
+ case '<': /* multinational charset (IGNORED) */
+ case '5': /* Finnish (IGNORED) */
+ case 'C': /* Finnish (IGNORED) */
+ case 'K': /* German (IGNORED) */
+ break;
                         default:
                                 fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii);
                         }
_AT_@ -1700,10 +1727,14 @@
                                 strescseq.type = ascii;
                                 term.esc |= ESC_STR;
                                 break;
- case ')':
- case '(':
+ case '(': /* set primary charset G0 */
                                 term.esc |= ESC_ALTCHARSET;
                                 break;
+ case ')': /* set secondary charset G1 (IGNORED) */
+ case '*': /* set tertiary charset G2 (IGNORED) */
+ case '+': /* set quaternary charset G3 (IGNORED) */
+ term.esc = 0;
+ break;
                         case 'D': /* IND -- Linefeed */
                                 if(term.c.y == term.bot)
                                         tscrollup(term.top, 1);
_AT_@ -2067,7 +2098,6 @@
         int winx = BORDER+x*xw.cw, winy = BORDER+y*xw.ch + dc.font.ascent, width = charlen*xw.cw;
         Font *font = &dc.font;
         XGlyphInfo extents;
- int i;
 
         /* only switch default fg/bg if term is in RV mode */
         if(IS_SET(MODE_REVERSE)) {
_AT_@ -2093,16 +2123,6 @@
         XSetBackground(xw.dpy, dc.gc, dc.col[bg]);
         XSetForeground(xw.dpy, dc.gc, dc.col[fg]);
 
- if(base.mode & ATTR_GFX) {
- for(i = 0; i < bytelen; i++) {
- char c = gfx[(uint)s[i] % 256];
- if(c)
- s[i] = c;
- else if(s[i] > 0x5f)
- s[i] -= 0x5f;
- }
- }
-
         XftTextExtentsUtf8(xw.dpy, font->xft_set, (FcChar8 *)s, bytelen, &extents);
         width = extents.xOff;
         XftDrawRect(xw.xft_draw, &dc.xft_col[bg], winx, winy - font->ascent, width, xw.ch);
Received on Wed Sep 26 2012 - 20:24:24 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 26 2012 - 20:36:09 CEST