aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-06-06 15:33:39 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-06-06 15:33:39 -0700
commit55b9e38a7bee6dec42be835e91733d7f9cd8ccc4 (patch)
treeac7fa7375283add063f1173afacc1675ea644af7 /sys
parent254258b48b4ba761eae0a1563549e4f324564456 (diff)
change cursor color based on text
Diffstat (limited to 'sys')
-rw-r--r--sys/cmd/term/config.h38
-rw-r--r--sys/cmd/term/term.c128
-rw-r--r--sys/cmd/term/term.h4
-rw-r--r--sys/cmd/term/x.c110
4 files changed, 136 insertions, 144 deletions
diff --git a/sys/cmd/term/config.h b/sys/cmd/term/config.h
index e4b37ce..81b11b0 100644
--- a/sys/cmd/term/config.h
+++ b/sys/cmd/term/config.h
@@ -95,36 +95,36 @@ char *termname = "term-256color";
uint tabspaces = 4;
/* bg opacity */
-float alpha = 0.8;
+float alpha = 0.85;
/* Terminal colors (16 first used in escape sequence) */
static char *colorname[] = {
/* 8 normal colors */
- "black",
- "red3",
- "green3",
- "yellow3",
- "blue2",
- "magenta3",
- "cyan3",
- "gray90",
+ "#4e4e4e",
+ "#d68787",
+ "#5f865f",
+ "#d8af5f",
+ "#85add4",
+ "#d7afaf",
+ "#87afaf",
+ "#d0d0d0",
/* 8 bright colors */
- "gray50",
- "red",
- "green",
- "yellow",
- "#5c5cff",
- "magenta",
- "cyan",
- "white",
+ "#626262",
+ "#d75f87",
+ "#87af87",
+ "#ffd787",
+ "#add4fb",
+ "#ffafaf",
+ "#87d7d7",
+ "#e4e4e4",
[255] = 0,
/* more colors can be added after 255 to use with DefaultXX */
"#cccccc",
"#555555",
- "black",
+ "#3a3a3a",
};
@@ -156,7 +156,7 @@ static uint rows = 24;
/*
* Default colour and shape of the mouse cursor
*/
-static uint mouseshape = XC_xterm;
+static uint mouseshape = XC_left_ptr;
static uint mousefg = 7;
static uint mousebg = 0;
diff --git a/sys/cmd/term/term.c b/sys/cmd/term/term.c
index 4569394..c5212b3 100644
--- a/sys/cmd/term/term.c
+++ b/sys/cmd/term/term.c
@@ -19,76 +19,77 @@
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
/* forward declare functions */
-static void execsh(char *, char **);
-static void stty(char **);
-static void sigchld(int);
-static void ttywriteraw(char *, size_t);
-
-static void csidump(void);
-static void csihandle(void);
-static void csiparse(void);
-static void csireset(void);
-static int eschandle(uchar);
-static void strdump(void);
-static void strhandle(void);
-static void strparse(void);
-static void strreset(void);
-
-static void tprinter(char *, size_t);
-static void tdumpsel(void);
-static void tdumpline(int);
-static void tdump(void);
-static void tclearregion(int, int, int, int);
-static void tcursor(int);
-static void tdeletechar(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 tnewline(int);
-static void tputtab(int);
-static void tputc(rune);
-static void treset(void);
-static void tscrollup(int, int);
-static void tscrolldown(int, int);
-static void tsetattr(int *, int);
-static void tsetchar(rune, Letter *, int, int);
-static void tsetdirt(int, int);
-static void tsetscroll(int, int);
-static void tswapscreen(void);
-static void tsetmode(int, int, int *, int);
-static int twrite(char *, int, int);
-static void tfulldirt(void);
-static void tcontrolcode(uchar );
-static void tdectest(char );
-static void tdefutf8(char);
-static int32 tdefcolor(int *, int *, int);
-static void tdeftran(char);
-static void tstrsequence(uchar);
-
-static void drawregion(int, int, int, int);
-
-static void selnormalize(void);
-static void selscroll(int, int);
-static void selsnap(int *, int *, int);
-
-static char *base64dec(char *);
-static char base64dec_getc(char **);
+static void execsh(char *, char **);
+static void stty(char **);
+static void sigchld(int);
+static void ttywriteraw(char *, size_t);
+
+static void csidump(void);
+static void csihandle(void);
+static void csiparse(void);
+static void csireset(void);
+static int eschandle(uchar);
+static void strdump(void);
+static void strhandle(void);
+static void strparse(void);
+static void strreset(void);
+
+static void tprinter(char *, size_t);
+static void tdumpsel(void);
+static void tdumpline(int);
+static void tdump(void);
+static void tclearregion(int, int, int, int);
+static void tcursor(int);
+static void tdeletechar(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 tnewline(int);
+static void tputtab(int);
+static void tputc(rune);
+static void treset(void);
+static void tscrollup(int, int);
+static void tscrolldown(int, int);
+static void tsetattr(int *, int);
+static void tsetchar(rune, Letter *, int, int);
+static void tsetdirt(int, int);
+static void tsetscroll(int, int);
+static void tswapscreen(void);
+static void tsetmode(int, int, int *, int);
+static int twrite(char *, int, int);
+static void tfulldirt(void);
+static void tcontrolcode(uchar );
+static void tdectest(char );
+static void tdefutf8(char);
+static int32 tdefcolor(int *, int *, int);
+static void tdeftran(char);
+static void tstrsequence(uchar);
+
+static void drawregion(int, int, int, int);
+
+static void selnormalize(void);
+static void selscroll(int, int);
+static void selsnap(int *, int *, int);
+
+static char *base64dec(char *);
+static char base64dec_getc(char **);
static uintptr xwrite(int, char *, size_t);
extern int wcwidth(wchar_t wc);
-/* Globals */
-static Terminal term;
+/* globals */
+static Terminal term;
static Selection sel;
static CSIEscape csiescseq;
static STREscape strescseq;
-static int iofd = 1;
-static int cmdfd;
-static pid_t pid;
+static int iofd = 1;
+static int cmdfd;
+static pid_t pid;
+/* functions */
uintptr
xwrite(int fd, char *s, size_t len)
{
@@ -2383,8 +2384,7 @@ draw(void)
cx--;
drawregion(0, 0, term.col, term.row);
- xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
- term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
+ xdrawcursor(cx, term.c.y, term.line[term.c.y][cx], term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
term.ocx = cx;
term.ocy = term.c.y;
xfinishdraw();
diff --git a/sys/cmd/term/term.h b/sys/cmd/term/term.h
index deb494c..00a646a 100644
--- a/sys/cmd/term/term.h
+++ b/sys/cmd/term/term.h
@@ -153,8 +153,8 @@ typedef union Arg Arg;
struct Letter {
rune u; /* character code */
ushort mode; /* attribute flags */
- uint32_t fg; /* foreground */
- uint32_t bg; /* background */
+ uint32 fg; /* foreground */
+ uint32 bg; /* background */
};
struct Dot {
diff --git a/sys/cmd/term/x.c b/sys/cmd/term/x.c
index 460bf7f..d6ec1bb 100644
--- a/sys/cmd/term/x.c
+++ b/sys/cmd/term/x.c
@@ -747,8 +747,7 @@ xloadcolor(int i, char *name, Color *ncolor)
color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16));
color.green = color.blue = color.red;
}
- return XftColorAllocValue(xw.dpy, xw.vis,
- xw.cmap, &color, ncolor);
+ return XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, ncolor);
} else
name = colorname[i];
}
@@ -811,9 +810,7 @@ xsetcolorname(int x, char *name)
void
xclear(int x1, int y1, int x2, int y2)
{
- XftDrawRect(xw.draw,
- &dc.col[IS_SET(Wreverse)? defaultfg : defaultbg],
- x1, y1, x2-x1, y2-y1);
+ XftDrawRect(xw.draw, &dc.col[IS_SET(Wreverse)? defaultfg : defaultbg], x1, y1, x2-x1, y2-y1);
}
void
@@ -1133,11 +1130,11 @@ xinit(int cols, int rows)
/* Events */
xw.attrs.background_pixel = dc.col[defaultbg].pixel;
- xw.attrs.border_pixel = dc.col[defaultbg].pixel;
- xw.attrs.bit_gravity = NorthWestGravity;
- xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
- | ExposureMask | VisibilityChangeMask | StructureNotifyMask
- | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
+ xw.attrs.border_pixel = dc.col[defaultbg].pixel;
+ xw.attrs.bit_gravity = NorthWestGravity;
+ xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
+ | ExposureMask | VisibilityChangeMask | StructureNotifyMask
+ | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
xw.attrs.colormap = xw.cmap;
xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
@@ -1161,10 +1158,8 @@ xinit(int cols, int rows)
xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
/* input methods */
- if (!ximopen(xw.dpy)) {
- XRegisterIMInstantiateCallback(xw.dpy, nil, nil, nil,
- ximinstantiate, nil);
- }
+ if (!ximopen(xw.dpy))
+ XRegisterIMInstantiateCallback(xw.dpy, nil, nil, nil, ximinstantiate, nil);
/* white cursor, black outline */
cursor = XCreateFontCursor(xw.dpy, mouseshape);
@@ -1184,9 +1179,9 @@ xinit(int cols, int rows)
XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
- xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
+ xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
- xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
+ xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);
xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
@@ -1196,6 +1191,7 @@ xinit(int cols, int rows)
win.mode = Wnumlock;
resettitle();
xhints();
+
XMapWindow(xw.dpy, xw.win);
XSync(xw.dpy, False);
@@ -1213,8 +1209,8 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Letter *glyphs, int len, int x, int
{
float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp, yp;
ushort mode, prevmode = USHRT_MAX;
- Font *font = &dc.font;
- int frcflags = FRC_NORMAL;
+ Font *font = &dc.font;
+ int frcflags = FRC_NORMAL;
float runewidth = win.cw;
rune r;
FT_UInt glyphidx;
@@ -1255,10 +1251,10 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Letter *glyphs, int len, int x, int
/* Lookup character index with default font. */
glyphidx = XftCharIndex(xw.dpy, font->match, r);
if (glyphidx) {
- specs[numspecs].font = font->match;
+ specs[numspecs].font = font->match;
specs[numspecs].glyph = glyphidx;
- specs[numspecs].x = (short)xp;
- specs[numspecs].y = (short)yp;
+ specs[numspecs].x = (short)xp;
+ specs[numspecs].y = (short)yp;
xp += runewidth;
numspecs++;
continue;
@@ -1361,9 +1357,9 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
if (IS_TRUECOL(base.fg)) {
colfg.alpha = 0xffff;
- colfg.red = TRUERED(base.fg);
+ colfg.red = TRUERED(base.fg);
colfg.green = TRUEGREEN(base.fg);
- colfg.blue = TRUEBLUE(base.fg);
+ colfg.blue = TRUEBLUE(base.fg);
XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &truefg);
fg = &truefg;
} else {
@@ -1373,8 +1369,8 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
if (IS_TRUECOL(base.bg)) {
colbg.alpha = 0xffff;
colbg.green = TRUEGREEN(base.bg);
- colbg.red = TRUERED(base.bg);
- colbg.blue = TRUEBLUE(base.bg);
+ colbg.red = TRUERED(base.bg);
+ colbg.blue = TRUEBLUE(base.bg);
XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &truebg);
bg = &truebg;
} else {
@@ -1389,42 +1385,37 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
if (fg == &dc.col[defaultfg]) {
fg = &dc.col[defaultbg];
} else {
- colfg.red = ~fg->color.red;
+ colfg.red = ~fg->color.red;
colfg.green = ~fg->color.green;
- colfg.blue = ~fg->color.blue;
+ colfg.blue = ~fg->color.blue;
colfg.alpha = fg->color.alpha;
- XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg,
- &revfg);
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
fg = &revfg;
}
if (bg == &dc.col[defaultbg]) {
bg = &dc.col[defaultfg];
} else {
- colbg.red = ~bg->color.red;
+ colbg.red = ~bg->color.red;
colbg.green = ~bg->color.green;
- colbg.blue = ~bg->color.blue;
+ colbg.blue = ~bg->color.blue;
colbg.alpha = bg->color.alpha;
- XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg,
- &revbg);
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &revbg);
bg = &revbg;
}
}
if ((base.mode & Gboldfaint) == Gfaint) {
- colfg.red = fg->color.red / 2;
+ colfg.red = fg->color.red / 2;
colfg.green = fg->color.green / 2;
- colfg.blue = fg->color.blue / 2;
+ colfg.blue = fg->color.blue / 2;
colfg.alpha = fg->color.alpha;
XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
fg = &revfg;
}
- if (base.mode & Greverse) {
- temp = fg;
- fg = bg;
- bg = temp;
- }
+ if (base.mode & Greverse)
+ temp = fg, fg = bg, bg = temp;
if (base.mode & Gblink && win.mode & Wblink)
fg = bg;
@@ -1451,25 +1442,20 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
XftDrawRect(xw.draw, bg, winx, winy, width, win.ch);
/* Set the clip region because Xft is sometimes dirty. */
- r.x = 0;
- r.y = 0;
+ r.x = 0, r.y = 0;
r.height = win.ch;
- r.width = width;
+ r.width = width;
XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
/* Render the glyphs. */
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
/* Render underline and strikethrough. */
- if (base.mode & Gunline) {
- XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
- width, 1);
- }
+ if (base.mode & Gunline)
+ XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1, width, 1);
- if (base.mode & Gstruck) {
- XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
- width, 1);
- }
+ if (base.mode & Gstruck)
+ XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3, width, 1);
/* Reset clip to none. */
XftDrawSetClip(xw.draw, 0);
@@ -1505,10 +1491,10 @@ xdrawcursor(int cx, int cy, Letter g, int ox, int oy, Letter og)
if (IS_SET(Wreverse)) {
g.mode |= Greverse;
- g.bg = defaultfg;
+ g.bg = defaultfg;
if (selected(cx, cy)) {
drawcol = dc.col[defaultcs];
- g.fg = defaultrcs;
+ g.fg = defaultrcs;
} else {
drawcol = dc.col[defaultrcs];
g.fg = defaultcs;
@@ -1518,18 +1504,25 @@ xdrawcursor(int cx, int cy, Letter g, int ox, int oy, Letter og)
g.fg = defaultfg;
g.bg = defaultrcs;
} else {
- g.fg = defaultbg;
- g.bg = defaultcs;
+ g.fg = og.bg; //defaultbg;
+ g.bg = og.fg; //defaultcs;
+ if (IS_TRUECOL(og.fg)) {
+ drawcol.color.alpha = 0xffff;
+ drawcol.color.red = TRUERED(og.fg);
+ drawcol.color.green = TRUEGREEN(og.fg);
+ drawcol.color.blue = TRUEBLUE(og.fg);
+ goto drawnew;
+ }
}
drawcol = dc.col[g.bg];
}
- /* draw the new one */
+drawnew:
if (IS_SET(Wfocused)) {
switch (win.cursor) {
case 7: /* st extension */
g.u = 0x2603; /* snowman (U+2603) */
- /* FALLTHROUGH */
+ /* fallthrough */
case 0: /* Blinking Block */
case 1: /* Blinking Block (Default) */
case 2: /* Steady Block */
@@ -1539,8 +1532,7 @@ xdrawcursor(int cx, int cy, Letter g, int ox, int oy, Letter og)
case 4: /* Steady Underline */
XftDrawRect(xw.draw, &drawcol,
borderpx + cx * win.cw,
- borderpx + (cy + 1) * win.ch - \
- cursorthickness,
+ borderpx + (cy + 1) * win.ch - cursorthickness,
win.cw, cursorthickness);
break;
case 5: /* Blinking bar */