Xinqi Bao's Git
projects
/
st.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Add DECOM sequence
[st.git]
/
st.c
diff --git
a/st.c
b/st.c
index
67fa790
..
657fba7
100644
(file)
--- a/
st.c
+++ b/
st.c
@@
-97,6
+97,7
@@
enum cursor_movement {
enum cursor_state {
CURSOR_DEFAULT = 0,
CURSOR_WRAPNEXT = 1,
enum cursor_state {
CURSOR_DEFAULT = 0,
CURSOR_WRAPNEXT = 1,
+ CURSOR_ORIGIN = 2
};
enum glyph_state {
};
enum glyph_state {
@@
-300,6
+301,7
@@
static void tdeleteline(int);
static void tinsertblank(int);
static void tinsertblankline(int);
static void tmoveto(int, int);
static void tinsertblank(int);
static void tinsertblankline(int);
static void tmoveto(int, int);
+static void tmoveato(int x, int y);
static void tnew(int, int);
static void tnewline(int);
static void tputtab(bool);
static void tnew(int, int);
static void tnewline(int);
static void tputtab(bool);
@@
-1076,6
+1078,8
@@
treset(void) {
term.mode = MODE_WRAP;
tclearregion(0, 0, term.col-1, term.row-1);
term.mode = MODE_WRAP;
tclearregion(0, 0, term.col-1, term.row-1);
+ tmoveto(0, 0);
+ tcursor(CURSOR_SAVE);
}
void
}
void
@@
-1209,10
+1213,25
@@
csiparse(void) {
}
}
}
}
+/* for absolute user moves, when decom is set */
+void
+tmoveato(int x, int y) {
+ tmoveto(x, y + ((term.c.state & CURSOR_ORIGIN) ? term.top: 0));
+}
+
void
tmoveto(int x, int y) {
void
tmoveto(int x, int y) {
+ int miny, maxy;
+
+ if(term.c.state & CURSOR_ORIGIN) {
+ miny = term.top;
+ maxy = term.bot;
+ } else {
+ miny = 0;
+ maxy = term.row - 1;
+ }
LIMIT(x, 0, term.col-1);
LIMIT(x, 0, term.col-1);
- LIMIT(y,
0, term.row-1
);
+ LIMIT(y,
miny, maxy
);
term.c.state &= ~CURSOR_WRAPNEXT;
term.c.x = x;
term.c.y = y;
term.c.state &= ~CURSOR_WRAPNEXT;
term.c.x = x;
term.c.y = y;
@@
-1454,7
+1473,9
@@
tsetmode(bool priv, bool set, int *args, int narg) {
if(mode != term.mode)
redraw();
break;
if(mode != term.mode)
redraw();
break;
- case 6: /* XXX: DECOM -- Origin */
+ case 6: /* DECOM -- Origin */
+ MODBIT(term.c.state, set, CURSOR_ORIGIN);
+ tmoveato(0, 0);
break;
case 7: /* DECAWM -- Auto wrap */
MODBIT(term.mode, set, MODE_WRAP);
break;
case 7: /* DECAWM -- Auto wrap */
MODBIT(term.mode, set, MODE_WRAP);
@@
-1475,15
+1496,15
@@
tsetmode(bool priv, bool set, int *args, int narg) {
break;
case 1049: /* = 1047 and 1048 */
case 47:
break;
case 1049: /* = 1047 and 1048 */
case 47:
- case 1047:
- if(IS_SET(MODE_ALTSCREEN))
+ case 1047: {
+ bool alt = IS_SET(MODE_ALTSCREEN) != 0;
+ if(alt)
tclearregion(0, 0, term.col-1, term.row-1);
tclearregion(0, 0, term.col-1, term.row-1);
- if((set && !IS_SET(MODE_ALTSCREEN)) ||
- (!set && IS_SET(MODE_ALTSCREEN))) {
+ if(set ^ alt) /* set is always 1 or 0 */
tswapscreen();
tswapscreen();
- }
if(*args != 1049)
break;
if(*args != 1049)
break;
+ }
/* pass through */
case 1048:
tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
/* pass through */
case 1048:
tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
@@
-1591,7
+1612,7
@@
csihandle(void) {
case 'f': /* HVP */
DEFAULT(csiescseq.arg[0], 1);
DEFAULT(csiescseq.arg[1], 1);
case 'f': /* HVP */
DEFAULT(csiescseq.arg[0], 1);
DEFAULT(csiescseq.arg[1], 1);
- tmoveto(csiescseq.arg[1]-1, csiescseq.arg[0]-1);
+ tmove
a
to(csiescseq.arg[1]-1, csiescseq.arg[0]-1);
break;
case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */
DEFAULT(csiescseq.arg[0], 1);
break;
case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */
DEFAULT(csiescseq.arg[0], 1);
@@
-1665,7
+1686,7
@@
csihandle(void) {
break;
case 'd': /* VPA -- Move to <row> */
DEFAULT(csiescseq.arg[0], 1);
break;
case 'd': /* VPA -- Move to <row> */
DEFAULT(csiescseq.arg[0], 1);
- tmoveto(term.c.x, csiescseq.arg[0]-1);
+ tmove
a
to(term.c.x, csiescseq.arg[0]-1);
break;
case 'h': /* SM -- Set terminal mode */
tsetmode(csiescseq.priv, 1, csiescseq.arg, csiescseq.narg);
break;
case 'h': /* SM -- Set terminal mode */
tsetmode(csiescseq.priv, 1, csiescseq.arg, csiescseq.narg);
@@
-1680,7
+1701,7
@@
csihandle(void) {
DEFAULT(csiescseq.arg[0], 1);
DEFAULT(csiescseq.arg[1], term.row);
tsetscroll(csiescseq.arg[0]-1, csiescseq.arg[1]-1);
DEFAULT(csiescseq.arg[0], 1);
DEFAULT(csiescseq.arg[1], term.row);
tsetscroll(csiescseq.arg[0]-1, csiescseq.arg[1]-1);
- tmoveto(0, 0);
+ tmove
a
to(0, 0);
}
break;
case 's': /* DECSC -- Save cursor position (ANSI.SYS) */
}
break;
case 's': /* DECSC -- Save cursor position (ANSI.SYS) */
@@
-2117,10
+2138,10
@@
tresize(int col, int row) {
/* update terminal size */
term.col = col;
term.row = row;
/* update terminal size */
term.col = col;
term.row = row;
- /* make use of the LIMIT in tmoveto */
- tmoveto(term.c.x, term.c.y);
/* reset scrolling region */
tsetscroll(0, row-1);
/* reset scrolling region */
tsetscroll(0, row-1);
+ /* make use of the LIMIT in tmoveto */
+ tmoveto(term.c.x, term.c.y);
return (slide > 0);
}
return (slide > 0);
}
@@
-2546,9
+2567,9
@@
drawregion(int x1, int y1, int x2, int y2) {
int ic, ib, x, y, ox, sl;
Glyph base, new;
char buf[DRAW_BUF_SIZ];
int ic, ib, x, y, ox, sl;
Glyph base, new;
char buf[DRAW_BUF_SIZ];
- bool ena_sel = sel.bx != -1, alt = IS_SET(MODE_ALTSCREEN);
+ bool ena_sel = sel.bx != -1, alt = IS_SET(MODE_ALTSCREEN)
!= 0
;
- if((sel.alt
&& !alt) || (!sel.alt && alt)
)
+ if((sel.alt
!= 0) ^ alt
)
ena_sel = 0;
if(!(xw.state & WIN_VISIBLE))
return;
ena_sel = 0;
if(!(xw.state & WIN_VISIBLE))
return;