Xinqi Bao's Git
projects
/
st.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Render faint attribute
[st.git]
/
st.c
diff --git
a/st.c
b/st.c
index
17142a4
..
69ec122
100644
(file)
--- a/
st.c
+++ b/
st.c
@@
-76,8
+76,7
@@
char *argv0;
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
#define IS_SET(flag) ((term.mode & (flag)) != 0)
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
#define IS_SET(flag) ((term.mode & (flag)) != 0)
-#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_nsec-t2.tv_nsec)/10E6)
-#define CEIL(x) (((x) != (int) (x)) ? (x) + 1 : (x))
+#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_nsec-t2.tv_nsec)/1E6)
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
@@
-90,15
+89,19
@@
char *argv0;
#define VT102ID "\033[?6c"
enum glyph_attribute {
#define VT102ID "\033[?6c"
enum glyph_attribute {
- ATTR_NULL = 0,
- ATTR_
REVERSE
= 1,
- ATTR_
UNDERLINE
= 2,
- ATTR_
BOLD
= 4,
- ATTR_
ITALIC
= 8,
+
ATTR_NULL = 0,
+ ATTR_
BOLD
= 1,
+ ATTR_
FAINT
= 2,
+ ATTR_
ITALIC
= 4,
+ ATTR_
UNDERLINE
= 8,
ATTR_BLINK = 16,
ATTR_BLINK = 16,
- ATTR_WRAP = 32,
- ATTR_WIDE = 64,
- ATTR_WDUMMY = 128,
+ ATTR_FASTBLINK = 32,
+ ATTR_REVERSE = 64,
+ ATTR_INVISIBLE = 128,
+ ATTR_STRUCK = 256,
+ ATTR_WRAP = 512,
+ ATTR_WIDE = 1024,
+ ATTR_WDUMMY = 2048,
};
enum cursor_movement {
};
enum cursor_movement {
@@
-372,6
+375,7
@@
static void tdeletechar(int);
static void tdeleteline(int);
static void tinsertblank(int);
static void tinsertblankline(int);
static void tdeleteline(int);
static void tinsertblank(int);
static void tinsertblankline(int);
+static int tlinelen(int);
static void tmoveto(int, int);
static void tmoveato(int, int);
static void tnew(int, int);
static void tmoveto(int, int);
static void tmoveato(int, int);
static void tnew(int, int);
@@
-917,7
+921,7
@@
bpress(XEvent *e) {
char *
getsel(void) {
char *str, *ptr;
char *
getsel(void) {
char *str, *ptr;
- int
x, y, bufsize, size, ex
;
+ int
y, bufsize, size, lastx, linelen
;
Glyph *gp, *last;
if(sel.ob.x == -1)
Glyph *gp, *last;
if(sel.ob.x == -1)
@@
-928,16
+932,19
@@
getsel(void) {
/* append every set & selected glyph to the selection */
for(y = sel.nb.y; y < sel.ne.y + 1; y++) {
/* append every set & selected glyph to the selection */
for(y = sel.nb.y; y < sel.ne.y + 1; y++) {
- gp = &term.line[y][0];
- last = &gp[term.col-1];
+ linelen = tlinelen(y);
- while(last >= gp && !(selected(last - gp, y) &&
- strcmp(last->c, " ") != 0)) {
- --last;
+ if(sel.type == SEL_RECTANGULAR) {
+ gp = &term.line[y][sel.nb.x];
+ lastx = sel.ne.x;
+ } else {
+ gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
+ lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
}
}
+ last = &term.line[y][MIN(lastx, linelen-1)];
- for(
x = 0; gp <= last; x++,
++gp) {
- if(
!selected(x, y) || (gp->mode & ATTR_WDUMMY)
)
+ for(
; gp <= last;
++gp) {
+ if(
gp->mode & ATTR_WDUMMY
)
continue;
size = utf8len(gp->c);
continue;
size = utf8len(gp->c);
@@
-954,20
+961,8
@@
getsel(void) {
* st.
* FIXME: Fix the computer world.
*/
* st.
* FIXME: Fix the computer world.
*/
- if(
y < sel.ne.y && !(x > 0 && (gp-1)->mode & ATTR_WRAP)
)
+ if(
sel.ne.y > y || lastx >= linelen
)
*ptr++ = '\n';
*ptr++ = '\n';
-
- /*
- * If the last selected line expands in the selection
- * after the visible text '\n' is appended.
- */
- if(y == sel.ne.y) {
- ex = sel.ne.x;
- if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x)
- ex = sel.nb.x;
- if(tlinelen(y) < ex)
- *ptr++ = '\n';
- }
}
*ptr = 0;
return str;
}
*ptr = 0;
return str;
@@
-1682,15
+1677,25
@@
tsetattr(int *attr, int l) {
for(i = 0; i < l; i++) {
switch(attr[i]) {
case 0:
for(i = 0; i < l; i++) {
switch(attr[i]) {
case 0:
- term.c.attr.mode &= ~(ATTR_REVERSE | ATTR_UNDERLINE \
- | ATTR_BOLD | ATTR_ITALIC \
- | ATTR_BLINK);
+ term.c.attr.mode &= ~(
+ ATTR_BOLD |
+ ATTR_FAINT |
+ ATTR_ITALIC |
+ ATTR_UNDERLINE |
+ ATTR_BLINK |
+ ATTR_FASTBLINK |
+ ATTR_REVERSE |
+ ATTR_INVISIBLE |
+ ATTR_STRUCK );
term.c.attr.fg = defaultfg;
term.c.attr.bg = defaultbg;
break;
case 1:
term.c.attr.mode |= ATTR_BOLD;
break;
term.c.attr.fg = defaultfg;
term.c.attr.bg = defaultbg;
break;
case 1:
term.c.attr.mode |= ATTR_BOLD;
break;
+ case 2:
+ term.c.attr.mode |= ATTR_FAINT;
+ break;
case 3:
term.c.attr.mode |= ATTR_ITALIC;
break;
case 3:
term.c.attr.mode |= ATTR_ITALIC;
break;
@@
-1698,16
+1703,26
@@
tsetattr(int *attr, int l) {
term.c.attr.mode |= ATTR_UNDERLINE;
break;
case 5: /* slow blink */
term.c.attr.mode |= ATTR_UNDERLINE;
break;
case 5: /* slow blink */
- case 6: /* rapid blink */
term.c.attr.mode |= ATTR_BLINK;
break;
term.c.attr.mode |= ATTR_BLINK;
break;
+ case 6: /* rapid blink */
+ term.c.attr.mode |= ATTR_FASTBLINK;
+ break;
case 7:
term.c.attr.mode |= ATTR_REVERSE;
break;
case 7:
term.c.attr.mode |= ATTR_REVERSE;
break;
+ case 8:
+ term.c.attr.mode |= ATTR_INVISIBLE;
+ break;
+ case 9:
+ term.c.attr.mode |= ATTR_STRUCK;
+ break;
case 21:
case 21:
- case 22:
term.c.attr.mode &= ~ATTR_BOLD;
break;
term.c.attr.mode &= ~ATTR_BOLD;
break;
+ case 22:
+ term.c.attr.mode &= ~ATTR_FAINT;
+ break;
case 23:
term.c.attr.mode &= ~ATTR_ITALIC;
break;
case 23:
term.c.attr.mode &= ~ATTR_ITALIC;
break;
@@
-1715,12
+1730,20
@@
tsetattr(int *attr, int l) {
term.c.attr.mode &= ~ATTR_UNDERLINE;
break;
case 25:
term.c.attr.mode &= ~ATTR_UNDERLINE;
break;
case 25:
- case 26:
term.c.attr.mode &= ~ATTR_BLINK;
break;
term.c.attr.mode &= ~ATTR_BLINK;
break;
+ case 26:
+ term.c.attr.mode &= ~ATTR_FASTBLINK;
+ break;
case 27:
term.c.attr.mode &= ~ATTR_REVERSE;
break;
case 27:
term.c.attr.mode &= ~ATTR_REVERSE;
break;
+ case 28:
+ term.c.attr.mode &= ~ATTR_INVISIBLE;
+ break;
+ case 29:
+ term.c.attr.mode &= ~ATTR_STRUCK;
+ break;
case 38:
if ((idx = tdefcolor(attr, &i, l)) >= 0)
term.c.attr.fg = idx;
case 38:
if ((idx = tdefcolor(attr, &i, l)) >= 0)
term.c.attr.fg = idx;
@@
-2256,12
+2279,10
@@
tdumpline(int n) {
Glyph *bp, *end;
bp = &term.line[n][0];
Glyph *bp, *end;
bp = &term.line[n][0];
- end = &bp[term.col-1];
- while(end > bp && !strcmp(" ", end->c))
- --end;
- if(bp != end || strcmp(bp->c, " ")) {
+ end = &bp[MIN(tlinelen(n), term.col) - 1];
+ if(bp != end || bp->c[0] != ' ') {
for( ;bp <= end; ++bp)
for( ;bp <= end; ++bp)
- tprinter(bp->c,
str
len(bp->c));
+ tprinter(bp->c,
utf8
len(bp->c));
}
tprinter("\n", 1);
}
}
tprinter("\n", 1);
}
@@
-2892,6
+2913,7
@@
xloadfonts(char *fontstr, double fontsize) {
FcPattern *pattern;
FcResult r_sz, r_psz;
double fontval;
FcPattern *pattern;
FcResult r_sz, r_psz;
double fontval;
+ float ceilf(float);
if(fontstr[0] == '-') {
pattern = XftXlfdParse(fontstr, False, False);
if(fontstr[0] == '-') {
pattern = XftXlfdParse(fontstr, False, False);
@@
-2937,8
+2959,8
@@
xloadfonts(char *fontstr, double fontsize) {
}
/* Setting character width and height. */
}
/* Setting character width and height. */
- xw.cw =
CEIL
(dc.font.width * cwscale);
- xw.ch =
CEIL
(dc.font.height * chscale);
+ xw.cw =
ceilf
(dc.font.width * cwscale);
+ xw.ch =
ceilf
(dc.font.height * chscale);
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
@@
-3157,7
+3179,7
@@
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
* change basic system colors [0-7]
* to bright system colors [8-15]
*/
* change basic system colors [0-7]
* to bright system colors [8-15]
*/
- if(BETWEEN(base.fg, 0, 7))
+ if(BETWEEN(base.fg, 0, 7)
&& !(base.mode & ATTR_FAINT)
)
fg = &dc.col[base.fg + 8];
if(base.mode & ATTR_ITALIC) {
fg = &dc.col[base.fg + 8];
if(base.mode & ATTR_ITALIC) {
@@
-3201,9
+3223,20
@@
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
bg = temp;
}
bg = temp;
}
+ if(base.mode & ATTR_FAINT && !(base.mode & ATTR_BOLD)) {
+ colfg.red = fg->color.red / 2;
+ colfg.green = fg->color.green / 2;
+ colfg.blue = fg->color.blue / 2;
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
+ fg = &revfg;
+ }
+
if(base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
fg = bg;
if(base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
fg = bg;
+ if(base.mode & ATTR_INVISIBLE)
+ fg = bg;
+
/* Intelligent cleaning up of the borders. */
if(x == 0) {
xclear(0, (y == 0)? 0 : winy, borderpx,
/* Intelligent cleaning up of the borders. */
if(x == 0) {
xclear(0, (y == 0)? 0 : winy, borderpx,
@@
-3348,6
+3381,11
@@
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
width, 1);
}
width, 1);
}
+ if(base.mode & ATTR_STRUCK) {
+ XftDrawRect(xw.draw, fg, winx, winy + 2 * font->ascent / 3,
+ width, 1);
+ }
+
/* Reset clip to none. */
XftDrawSetClip(xw.draw, 0);
}
/* Reset clip to none. */
XftDrawSetClip(xw.draw, 0);
}
@@
-3753,7
+3791,7
@@
run(void) {
clock_gettime(CLOCK_MONOTONIC, &now);
drawtimeout.tv_sec = 0;
clock_gettime(CLOCK_MONOTONIC, &now);
drawtimeout.tv_sec = 0;
- drawtimeout.tv_nsec = (1000/xfps) * 1
0
E6;
+ drawtimeout.tv_nsec = (1000/xfps) * 1E6;
tv = &drawtimeout;
dodraw = 0;
tv = &drawtimeout;
dodraw = 0;
@@
-3790,7
+3828,7
@@
run(void) {
> blinktimeout) {
drawtimeout.tv_nsec = 1000;
} else {
> blinktimeout) {
drawtimeout.tv_nsec = 1000;
} else {
- drawtimeout.tv_nsec = (1
0
E6 * \
+ drawtimeout.tv_nsec = (1E6 * \
(blinktimeout - \
TIMEDIFF(now,
lastblink)));
(blinktimeout - \
TIMEDIFF(now,
lastblink)));