moved term.hidec in term.c for consistency, put back delay in xbell()

along with duration in config.h, factored some code in tnew()/treset()
and cleaned some code.
This commit is contained in:
Aurélien Aptel 2010-08-29 18:55:15 +02:00
parent c186c8ef9a
commit 2181040594
2 changed files with 21 additions and 28 deletions

View File

@ -30,6 +30,7 @@ static const char *colorname[] = {
#define DefaultBG 0 #define DefaultBG 0
#define DefaultCS 1 #define DefaultCS 1
#define BellCol DefaultFG #define BellCol DefaultFG
#define BellTime 30000 /* microseconds */
/* special keys */ /* special keys */
static Key key[] = { static Key key[] = {

48
st.c
View File

@ -67,6 +67,7 @@ typedef struct {
Glyph attr; /* current char attributes */ Glyph attr; /* current char attributes */
int x; int x;
int y; int y;
char hide;
} TCursor; } TCursor;
/* CSI Escape sequence structs */ /* CSI Escape sequence structs */
@ -86,7 +87,6 @@ typedef struct {
int col; /* nb col */ int col; /* nb col */
Line* line; /* screen */ Line* line; /* screen */
TCursor c; /* cursor */ TCursor c; /* cursor */
char hidec;
int top; /* top scroll limit */ int top; /* top scroll limit */
int bot; /* bottom scroll limit */ int bot; /* bottom scroll limit */
int mode; /* terminal mode flags */ int mode; /* terminal mode flags */
@ -221,17 +221,16 @@ die(const char *errstr, ...) {
void void
execsh(void) { execsh(void) {
char *args[3] = {getenv("SHELL"), "-i", NULL}; char *args[3] = {getenv("SHELL"), "-i", NULL};
DEFAULT(args[0], "/bin/sh"); /* default shell if getenv() failed */ DEFAULT(args[0], "/bin/sh"); /* if getenv() failed */
putenv("TERM=" TNAME); putenv("TERM=" TNAME);
execvp(args[0], args); execvp(args[0], args);
} }
void void
xbell(void) { /* visual bell */ xbell(void) {
XRectangle r = { BORDER, BORDER, xw.bufw, xw.bufh };
XSetForeground(xw.dis, dc.gc, dc.col[BellCol]); XSetForeground(xw.dis, dc.gc, dc.col[BellCol]);
XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1); XFillRectangle(xw.dis, xw.win, dc.gc, BORDER, BORDER, xw.bufw, xw.bufh);
/* usleep(30000); */ usleep(BellTime);
draw(SCREEN_REDRAW); draw(SCREEN_REDRAW);
} }
@ -325,11 +324,12 @@ tcursor(int mode) {
void void
treset(void) { treset(void) {
term.c.attr.mode = ATTR_NULL; term.c = (TCursor){{
term.c.attr.fg = DefaultFG; .mode = ATTR_NULL,
term.c.attr.bg = DefaultBG; .fg = DefaultFG,
term.c.x = term.c.y = 0; .bg = DefaultBG
term.hidec = 0; }, .x = 0, .y = 0, .hide = 0};
term.top = 0, term.bot = term.row - 1; term.top = 0, term.bot = term.row - 1;
term.mode = MODE_WRAP; term.mode = MODE_WRAP;
tclearregion(0, 0, term.col-1, term.row-1); tclearregion(0, 0, term.col-1, term.row-1);
@ -337,21 +337,13 @@ treset(void) {
void void
tnew(int col, int row) { tnew(int col, int row) {
/* screen size */ /* set screen size */
term.row = row, term.col = col; term.row = row, term.col = col;
term.top = 0, term.bot = term.row - 1; term.line = malloc(term.row * sizeof(Line));
/* mode */
term.mode = MODE_WRAP;
/* cursor */
term.c.attr.mode = ATTR_NULL;
term.c.attr.fg = DefaultFG;
term.c.attr.bg = DefaultBG;
term.c.x = term.c.y = 0;
term.hidec = 0;
/* allocate screen */
term.line = calloc(term.row, sizeof(Line));
for(row = 0 ; row < term.row; row++) for(row = 0 ; row < term.row; row++)
term.line[row] = calloc(term.col, sizeof(Glyph)); term.line[row] = malloc(term.col * sizeof(Glyph));
/* setup screen */
treset();
} }
void void
@ -718,7 +710,7 @@ csihandle(void) {
case 12: /* att610 -- Stop blinking cursor (IGNORED) */ case 12: /* att610 -- Stop blinking cursor (IGNORED) */
break; break;
case 25: case 25:
term.hidec = 1; term.c.hide = 1;
break; break;
case 1048: /* XXX: no alt. screen to erase/save */ case 1048: /* XXX: no alt. screen to erase/save */
case 1049: case 1049:
@ -767,7 +759,7 @@ csihandle(void) {
case 12: /* att610 -- Start blinking cursor (IGNORED) */ case 12: /* att610 -- Start blinking cursor (IGNORED) */
break; break;
case 25: case 25:
term.hidec = 0; term.c.hide = 0;
break; break;
case 1048: case 1048:
case 1049: /* XXX: no alt. screen to erase/save */ case 1049: /* XXX: no alt. screen to erase/save */
@ -1173,7 +1165,7 @@ draw(int dummy) {
if(term.line[y][x].state & GLYPH_SET) if(term.line[y][x].state & GLYPH_SET)
xdrawc(x, y, term.line[y][x]); xdrawc(x, y, term.line[y][x]);
if(!term.hidec) if(!term.c.hide)
xcursor(CURSOR_DRAW); xcursor(CURSOR_DRAW);
XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
XFlush(xw.dis); XFlush(xw.dis);
@ -1206,7 +1198,7 @@ draw(int redraw_all) {
} }
xdraws(buf, base, ox, y, i); xdraws(buf, base, ox, y, i);
} }
xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW); xcursor(term.c.hide ? CURSOR_HIDE : CURSOR_DRAW);
XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
XFlush(xw.dis); XFlush(xw.dis);
} }