Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
80a46b1270 | |||
664c40f6bc | |||
6cd5c3dab7 | |||
8ebab41592 | |||
1ec0515e75 | |||
adf5d2e32a | |||
62d380947e | |||
5705e5dfd1 | |||
45971204a2 | |||
e478f91c10 | |||
284430538d | |||
c7ed0d1bad |
1
.hgtags
1
.hgtags
@ -1,2 +1,3 @@
|
|||||||
cbc18c988236c63a58ed24031805e8d36a3ad01a 0.1
|
cbc18c988236c63a58ed24031805e8d36a3ad01a 0.1
|
||||||
f245ac2efd8ac2f1ac6bffae876c2663e794f79d 0.1.1
|
f245ac2efd8ac2f1ac6bffae876c2663e794f79d 0.1.1
|
||||||
|
3c2f9f2ab5e433db1401047760ec31d66939b74b 0.2
|
||||||
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2009, Aurélien APTEL <aurelien dot aptel at gmail dot com>
|
Copyright (c) 2009-2012, Aurélien APTEL <aurelien dot aptel at gmail dot com>
|
||||||
Copyright (c) 2009, Anselm R Garbe <garbeam at gmail dot com>
|
Copyright (c) 2009, Anselm R Garbe <garbeam at gmail dot com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
7
TODO
7
TODO
@ -10,10 +10,15 @@ code & interface
|
|||||||
|
|
||||||
* clean selection code
|
* clean selection code
|
||||||
* clean and complete terminfo entry
|
* clean and complete terminfo entry
|
||||||
* fix shift up/down (shift selection in emacs)
|
|
||||||
* fast drawing
|
* fast drawing
|
||||||
* ...
|
* ...
|
||||||
|
|
||||||
|
bugs
|
||||||
|
----
|
||||||
|
|
||||||
|
* handle XOpenMI() errors
|
||||||
|
* fix shift up/down (shift selection in emacs)
|
||||||
|
|
||||||
misc
|
misc
|
||||||
----
|
----
|
||||||
|
|
||||||
|
32
config.def.h
32
config.def.h
@ -1,12 +1,16 @@
|
|||||||
#define TAB 8
|
|
||||||
#define TNAME "st-256color"
|
|
||||||
#define FONT "-*-*-medium-r-*-*-*-120-75-75-*-60-*-*"
|
#define FONT "-*-*-medium-r-*-*-*-120-75-75-*-60-*-*"
|
||||||
#define BOLDFONT "-*-*-bold-r-*-*-*-120-75-75-*-60-*-*"
|
#define BOLDFONT "-*-*-bold-r-*-*-*-120-75-75-*-60-*-*"
|
||||||
|
|
||||||
|
/* Space in pixels around the terminal buffer */
|
||||||
#define BORDER 2
|
#define BORDER 2
|
||||||
|
|
||||||
|
/* Default shell to use if SHELL is not set in the env */
|
||||||
#define SHELL "/bin/sh"
|
#define SHELL "/bin/sh"
|
||||||
|
|
||||||
/* Terminal colors (16 first used in escape sequence) */
|
/* Terminal colors (16 first used in escape sequence) */
|
||||||
static const char *colorname[] = {
|
static const char *colorname[] = {
|
||||||
|
/* 8 normal colors */
|
||||||
"black",
|
"black",
|
||||||
"red3",
|
"red3",
|
||||||
"green3",
|
"green3",
|
||||||
@ -15,6 +19,8 @@ static const char *colorname[] = {
|
|||||||
"magenta3",
|
"magenta3",
|
||||||
"cyan3",
|
"cyan3",
|
||||||
"gray90",
|
"gray90",
|
||||||
|
|
||||||
|
/* 8 bright colors */
|
||||||
"gray50",
|
"gray50",
|
||||||
"red",
|
"red",
|
||||||
"green",
|
"green",
|
||||||
@ -22,14 +28,21 @@ static const char *colorname[] = {
|
|||||||
"#5c5cff",
|
"#5c5cff",
|
||||||
"magenta",
|
"magenta",
|
||||||
"cyan",
|
"cyan",
|
||||||
"white"
|
"white",
|
||||||
|
|
||||||
|
[255] = 0,
|
||||||
|
|
||||||
|
/* more colors can be added after 255 to use with DefaultXX */
|
||||||
|
"#cccccc",
|
||||||
|
"#333333",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Default colors (colorname index)
|
/* Default colors (colorname index)
|
||||||
foreground, background, cursor */
|
foreground, background, cursor, unfocused cursor */
|
||||||
#define DefaultFG 7
|
#define DefaultFG 7
|
||||||
#define DefaultBG 0
|
#define DefaultBG 0
|
||||||
#define DefaultCS 1
|
#define DefaultCS 256
|
||||||
|
#define DefaultUCS 257
|
||||||
|
|
||||||
/* Special keys (change & recompile st.info accordingly)
|
/* Special keys (change & recompile st.info accordingly)
|
||||||
Keep in mind that kpress() in st.c hardcodes some keys.
|
Keep in mind that kpress() in st.c hardcodes some keys.
|
||||||
@ -61,6 +74,9 @@ static Key key[] = {
|
|||||||
{ XK_F12, XK_NO_MOD, "\033[24~" },
|
{ XK_F12, XK_NO_MOD, "\033[24~" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Set TERM to this */
|
||||||
|
#define TNAME "st-256color"
|
||||||
|
|
||||||
/* Line drawing characters (sometime specific to each font...) */
|
/* Line drawing characters (sometime specific to each font...) */
|
||||||
static char gfx[] = {
|
static char gfx[] = {
|
||||||
['f'] = 'o',
|
['f'] = 'o',
|
||||||
@ -72,3 +88,5 @@ static char gfx[] = {
|
|||||||
/* double-click timeout (in milliseconds) between clicks for selection */
|
/* double-click timeout (in milliseconds) between clicks for selection */
|
||||||
#define DOUBLECLICK_TIMEOUT 300
|
#define DOUBLECLICK_TIMEOUT 300
|
||||||
#define TRIPLECLICK_TIMEOUT (2*DOUBLECLICK_TIMEOUT)
|
#define TRIPLECLICK_TIMEOUT (2*DOUBLECLICK_TIMEOUT)
|
||||||
|
|
||||||
|
#define TAB 8
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# st version
|
# st version
|
||||||
VERSION = 0.1.1
|
VERSION = 0.2.1
|
||||||
|
|
||||||
# Customize below to fit your system
|
# Customize below to fit your system
|
||||||
|
|
||||||
|
155
st.c
155
st.c
@ -34,7 +34,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define USAGE \
|
#define USAGE \
|
||||||
"st " VERSION " (c) 2010-2011 st engineers\n" \
|
"st " VERSION " (c) 2010-2012 st engineers\n" \
|
||||||
"usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n"
|
"usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n"
|
||||||
|
|
||||||
/* XEMBED messages */
|
/* XEMBED messages */
|
||||||
@ -66,30 +66,75 @@
|
|||||||
#define X2COL(x) (((x) - BORDER)/xw.cw)
|
#define X2COL(x) (((x) - BORDER)/xw.cw)
|
||||||
#define Y2ROW(y) (((y) - BORDER)/xw.ch)
|
#define Y2ROW(y) (((y) - BORDER)/xw.ch)
|
||||||
|
|
||||||
/* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */
|
enum glyph_attribute {
|
||||||
enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 };
|
ATTR_NULL = 0,
|
||||||
enum { CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT,
|
ATTR_REVERSE = 1,
|
||||||
CURSOR_SAVE, CURSOR_LOAD };
|
ATTR_UNDERLINE = 2,
|
||||||
enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 };
|
ATTR_BOLD = 4,
|
||||||
enum { GLYPH_SET=1, GLYPH_DIRTY=2 };
|
ATTR_GFX = 8,
|
||||||
enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8,
|
};
|
||||||
MODE_CRLF=16, MODE_MOUSEBTN=32, MODE_MOUSEMOTION=64, MODE_MOUSE=32|64, MODE_REVERSE=128 };
|
|
||||||
enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 };
|
|
||||||
enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 };
|
|
||||||
|
|
||||||
|
enum cursor_movement {
|
||||||
|
CURSOR_UP,
|
||||||
|
CURSOR_DOWN,
|
||||||
|
CURSOR_LEFT,
|
||||||
|
CURSOR_RIGHT,
|
||||||
|
CURSOR_SAVE,
|
||||||
|
CURSOR_LOAD
|
||||||
|
};
|
||||||
|
|
||||||
|
enum cursor_state {
|
||||||
|
CURSOR_DEFAULT = 0,
|
||||||
|
CURSOR_HIDE = 1,
|
||||||
|
CURSOR_WRAPNEXT = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum glyph_state {
|
||||||
|
GLYPH_SET = 1,
|
||||||
|
GLYPH_DIRTY = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum term_mode {
|
||||||
|
MODE_WRAP = 1,
|
||||||
|
MODE_INSERT = 2,
|
||||||
|
MODE_APPKEYPAD = 4,
|
||||||
|
MODE_ALTSCREEN = 8,
|
||||||
|
MODE_CRLF = 16,
|
||||||
|
MODE_MOUSEBTN = 32,
|
||||||
|
MODE_MOUSEMOTION = 64,
|
||||||
|
MODE_MOUSE = 32|64,
|
||||||
|
MODE_REVERSE = 128
|
||||||
|
};
|
||||||
|
|
||||||
|
enum escape_state {
|
||||||
|
ESC_START = 1,
|
||||||
|
ESC_CSI = 2,
|
||||||
|
ESC_OSC = 4,
|
||||||
|
ESC_TITLE = 8,
|
||||||
|
ESC_ALTCHARSET = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
enum window_state {
|
||||||
|
WIN_VISIBLE = 1,
|
||||||
|
WIN_REDRAW = 2,
|
||||||
|
WIN_FOCUSED = 4
|
||||||
|
};
|
||||||
|
|
||||||
|
/* bit macro */
|
||||||
#undef B0
|
#undef B0
|
||||||
enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 };
|
enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 };
|
||||||
|
|
||||||
typedef unsigned char uchar;
|
typedef unsigned char uchar;
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
typedef unsigned long ulong;
|
typedef unsigned long ulong;
|
||||||
|
typedef unsigned short ushort;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char c[UTF_SIZ]; /* character code */
|
char c[UTF_SIZ]; /* character code */
|
||||||
char mode; /* attribute flags */
|
uchar mode; /* attribute flags */
|
||||||
int fg; /* foreground */
|
ushort fg; /* foreground */
|
||||||
int bg; /* background */
|
ushort bg; /* background */
|
||||||
char state; /* state flags */
|
uchar state; /* state flags */
|
||||||
} Glyph;
|
} Glyph;
|
||||||
|
|
||||||
typedef Glyph* Line;
|
typedef Glyph* Line;
|
||||||
@ -154,18 +199,6 @@ typedef struct {
|
|||||||
char s[ESC_BUF_SIZ];
|
char s[ESC_BUF_SIZ];
|
||||||
} Key;
|
} Key;
|
||||||
|
|
||||||
/* Drawing Context */
|
|
||||||
typedef struct {
|
|
||||||
ulong col[256];
|
|
||||||
GC gc;
|
|
||||||
struct {
|
|
||||||
int ascent;
|
|
||||||
int descent;
|
|
||||||
short lbearing;
|
|
||||||
short rbearing;
|
|
||||||
XFontSet set;
|
|
||||||
} font, bfont;
|
|
||||||
} DC;
|
|
||||||
|
|
||||||
/* TODO: use better name for vars... */
|
/* TODO: use better name for vars... */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -181,6 +214,19 @@ typedef struct {
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
/* Drawing Context */
|
||||||
|
typedef struct {
|
||||||
|
ulong col[LEN(colorname) < 256 ? 256 : LEN(colorname)];
|
||||||
|
GC gc;
|
||||||
|
struct {
|
||||||
|
int ascent;
|
||||||
|
int descent;
|
||||||
|
short lbearing;
|
||||||
|
short rbearing;
|
||||||
|
XFontSet set;
|
||||||
|
} font, bfont;
|
||||||
|
} DC;
|
||||||
|
|
||||||
static void die(const char*, ...);
|
static void die(const char*, ...);
|
||||||
static void draw(void);
|
static void draw(void);
|
||||||
static void drawregion(int, int, int, int);
|
static void drawregion(int, int, int, int);
|
||||||
@ -1342,12 +1388,15 @@ csihandle(void) {
|
|||||||
void
|
void
|
||||||
csidump(void) {
|
csidump(void) {
|
||||||
int i;
|
int i;
|
||||||
printf("ESC [ %s", escseq.priv ? "? " : "");
|
printf("ESC[");
|
||||||
if(escseq.narg)
|
for(i = 0; i < escseq.len; i++) {
|
||||||
for(i = 0; i < escseq.narg; i++)
|
uint c = escseq.buf[i] & 0xff;
|
||||||
printf("%d ", escseq.arg[i]);
|
if(isprint(c)) putchar(c);
|
||||||
if(escseq.mode)
|
else if(c == '\n') printf("(\\n)");
|
||||||
putchar(escseq.mode);
|
else if(c == '\r') printf("(\\r)");
|
||||||
|
else if(c == 0x1b) printf("(\\e)");
|
||||||
|
else printf("(%02x)", c);
|
||||||
|
}
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1589,7 +1638,10 @@ xloadcols(void) {
|
|||||||
XColor color;
|
XColor color;
|
||||||
ulong white = WhitePixel(xw.dpy, xw.scr);
|
ulong white = WhitePixel(xw.dpy, xw.scr);
|
||||||
|
|
||||||
|
/* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */
|
||||||
for(i = 0; i < LEN(colorname); i++) {
|
for(i = 0; i < LEN(colorname); i++) {
|
||||||
|
if(!colorname[i])
|
||||||
|
continue;
|
||||||
if(!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, &color)) {
|
if(!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, &color)) {
|
||||||
dc.col[i] = white;
|
dc.col[i] = white;
|
||||||
fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]);
|
fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]);
|
||||||
@ -1597,8 +1649,8 @@ xloadcols(void) {
|
|||||||
dc.col[i] = color.pixel;
|
dc.col[i] = color.pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* same colors as xterm */
|
/* load colors [16-255] ; same colors as xterm */
|
||||||
for(r = 0; r < 6; r++)
|
for(i = 16, r = 0; r < 6; r++)
|
||||||
for(g = 0; g < 6; g++)
|
for(g = 0; g < 6; g++)
|
||||||
for(b = 0; b < 6; b++) {
|
for(b = 0; b < 6; b++) {
|
||||||
color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r;
|
color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r;
|
||||||
@ -1761,23 +1813,29 @@ xinit(void) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
|
xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
|
||||||
ulong xfg = dc.col[base.fg], xbg = dc.col[base.bg], temp;
|
int fg = base.fg, bg = base.bg, temp;
|
||||||
int winx = x*xw.cw, winy = y*xw.ch + dc.font.ascent, width = charlen*xw.cw;
|
int winx = x*xw.cw, winy = y*xw.ch + dc.font.ascent, width = charlen*xw.cw;
|
||||||
|
XFontSet fontset = dc.font.set;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* only switch default fg/bg if term is in RV mode */
|
/* only switch default fg/bg if term is in RV mode */
|
||||||
if(IS_SET(MODE_REVERSE)) {
|
if(IS_SET(MODE_REVERSE)) {
|
||||||
if(base.fg == DefaultFG)
|
if(fg == DefaultFG)
|
||||||
xfg = dc.col[DefaultBG];
|
fg = DefaultBG;
|
||||||
if(base.bg == DefaultBG)
|
if(bg == DefaultBG)
|
||||||
xbg = dc.col[DefaultFG];
|
bg = DefaultFG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(base.mode & ATTR_REVERSE)
|
if(base.mode & ATTR_REVERSE)
|
||||||
temp = xfg, xfg = xbg, xbg = temp;
|
temp = fg, fg = bg, bg = temp;
|
||||||
|
|
||||||
XSetBackground(xw.dpy, dc.gc, xbg);
|
if(base.mode & ATTR_BOLD) {
|
||||||
XSetForeground(xw.dpy, dc.gc, xfg);
|
fg += 8;
|
||||||
|
fontset = dc.bfont.set;
|
||||||
|
}
|
||||||
|
|
||||||
|
XSetBackground(xw.dpy, dc.gc, dc.col[bg]);
|
||||||
|
XSetForeground(xw.dpy, dc.gc, dc.col[fg]);
|
||||||
|
|
||||||
if(base.mode & ATTR_GFX) {
|
if(base.mode & ATTR_GFX) {
|
||||||
for(i = 0; i < bytelen; i++) {
|
for(i = 0; i < bytelen; i++) {
|
||||||
@ -1789,8 +1847,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XmbDrawImageString(xw.dpy, xw.buf, base.mode & ATTR_BOLD ? dc.bfont.set : dc.font.set,
|
XmbDrawImageString(xw.dpy, xw.buf, fontset, dc.gc, winx, winy, s, bytelen);
|
||||||
dc.gc, winx, winy, s, bytelen);
|
|
||||||
|
|
||||||
if(base.mode & ATTR_UNDERLINE)
|
if(base.mode & ATTR_UNDERLINE)
|
||||||
XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1);
|
XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1);
|
||||||
@ -1827,10 +1884,14 @@ xdrawcursor(void) {
|
|||||||
xcopy(oldx, oldy, 1, 1);
|
xcopy(oldx, oldy, 1, 1);
|
||||||
|
|
||||||
/* draw the new one */
|
/* draw the new one */
|
||||||
if(!(term.c.state & CURSOR_HIDE) && (xw.state & WIN_FOCUSED)) {
|
if(!(term.c.state & CURSOR_HIDE)) {
|
||||||
sl = utf8size(g.c);
|
if(!(xw.state & WIN_FOCUSED))
|
||||||
|
g.bg = DefaultUCS;
|
||||||
|
|
||||||
if(IS_SET(MODE_REVERSE))
|
if(IS_SET(MODE_REVERSE))
|
||||||
g.mode |= ATTR_REVERSE, g.fg = DefaultCS, g.bg = DefaultFG;
|
g.mode |= ATTR_REVERSE, g.fg = DefaultCS, g.bg = DefaultFG;
|
||||||
|
|
||||||
|
sl = utf8size(g.c);
|
||||||
xdraws(g.c, g, term.c.x, term.c.y, 1, sl);
|
xdraws(g.c, g, term.c.x, term.c.y, 1, sl);
|
||||||
oldx = term.c.x, oldy = term.c.y;
|
oldx = term.c.x, oldy = term.c.y;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user