summaryrefslogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
Diffstat (limited to 'st.c')
-rw-r--r--st.c180
1 files changed, 76 insertions, 104 deletions
diff --git a/st.c b/st.c
index 123d29e..f3f7f28 100644
--- a/st.c
+++ b/st.c
@@ -273,6 +273,7 @@ static void tsetchar(char*);
273static void tsetscroll(int, int); 273static void tsetscroll(int, int);
274static void tswapscreen(void); 274static void tswapscreen(void);
275static void tsetdirt(int, int); 275static void tsetdirt(int, int);
276static void tsetmode(bool, bool, int *, int);
276static void tfulldirt(void); 277static void tfulldirt(void);
277 278
278static void ttynew(void); 279static void ttynew(void);
@@ -1178,6 +1179,79 @@ tsetscroll(int t, int b) {
1178 term.bot = b; 1179 term.bot = b;
1179} 1180}
1180 1181
1182#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
1183
1184void
1185tsetmode(bool priv, bool set, int *args, int narg) {
1186 int *lim, mode;
1187
1188 for (lim = args + narg; args < lim; ++args) {
1189 if(priv) {
1190 switch(*args) {
1191 case 1:
1192 MODBIT(term.mode, set, MODE_APPKEYPAD);
1193 break;
1194 case 5: /* DECSCNM -- Reverve video */
1195 mode = term.mode;
1196 MODBIT(term.mode,set, MODE_REVERSE);
1197 if (mode != term.mode)
1198 draw();
1199 break;
1200 case 7:
1201 MODBIT(term.mode, set, MODE_WRAP);
1202 break;
1203 case 20:
1204 MODBIT(term.mode, set, MODE_CRLF);
1205 break;
1206 case 12: /* att610 -- Start blinking cursor (IGNORED) */
1207 break;
1208 case 25:
1209 MODBIT(term.c.state, !set, CURSOR_HIDE);
1210 break;
1211 case 1000: /* 1000,1002: enable xterm mouse report */
1212 MODBIT(term.mode, set, MODE_MOUSEBTN);
1213 break;
1214 case 1002:
1215 MODBIT(term.mode, set, MODE_MOUSEMOTION);
1216 break;
1217 case 1049: /* = 1047 and 1048 */
1218 case 47:
1219 case 1047:
1220 if(IS_SET(MODE_ALTSCREEN))
1221 tclearregion(0, 0, term.col-1, term.row-1);
1222 if ((set && !IS_SET(MODE_ALTSCREEN)) ||
1223 (!set && IS_SET(MODE_ALTSCREEN))) {
1224 tswapscreen();
1225 }
1226 if (*args != 1049)
1227 break;
1228 /* pass through */
1229 case 1048:
1230 tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
1231 break;
1232 default:
1233 fprintf(stderr,
1234 "erresc: unknown private set/reset mode %d\n",
1235 *args);
1236 break;
1237 }
1238 } else {
1239 switch(*args) {
1240 case 4:
1241 MODBIT(term.mode, set, MODE_INSERT);
1242 break;
1243 default:
1244 fprintf(stderr,
1245 "erresc: unknown set/reset mode %d\n",
1246 *args);
1247 break;
1248 }
1249 }
1250 }
1251}
1252#undef MODBIT
1253
1254
1181void 1255void
1182csihandle(void) { 1256csihandle(void) {
1183 switch(csiescseq.mode) { 1257 switch(csiescseq.mode) {
@@ -1291,58 +1365,7 @@ csihandle(void) {
1291 tinsertblankline(csiescseq.arg[0]); 1365 tinsertblankline(csiescseq.arg[0]);
1292 break; 1366 break;
1293 case 'l': /* RM -- Reset Mode */ 1367 case 'l': /* RM -- Reset Mode */
1294 if(csiescseq.priv) { 1368 tsetmode(csiescseq.priv, 0, csiescseq.arg, csiescseq.narg);
1295 switch(csiescseq.arg[0]) {
1296 case 1:
1297 term.mode &= ~MODE_APPKEYPAD;
1298 break;
1299 case 5: /* DECSCNM -- Remove reverse video */
1300 if(IS_SET(MODE_REVERSE)) {
1301 term.mode &= ~MODE_REVERSE;
1302 draw();
1303 }
1304 break;
1305 case 7:
1306 term.mode &= ~MODE_WRAP;
1307 break;
1308 case 12: /* att610 -- Stop blinking cursor (IGNORED) */
1309 break;
1310 case 20:
1311 term.mode &= ~MODE_CRLF;
1312 break;
1313 case 25:
1314 term.c.state |= CURSOR_HIDE;
1315 break;
1316 case 1000: /* disable X11 xterm mouse reporting */
1317 term.mode &= ~MODE_MOUSEBTN;
1318 break;
1319 case 1002:
1320 term.mode &= ~MODE_MOUSEMOTION;
1321 break;
1322 case 1049: /* = 1047 and 1048 */
1323 case 47:
1324 case 1047:
1325 if(IS_SET(MODE_ALTSCREEN)) {
1326 tclearregion(0, 0, term.col-1, term.row-1);
1327 tswapscreen();
1328 }
1329 if(csiescseq.arg[0] != 1049)
1330 break;
1331 case 1048:
1332 tcursor(CURSOR_LOAD);
1333 break;
1334 default:
1335 goto unknown;
1336 }
1337 } else {
1338 switch(csiescseq.arg[0]) {
1339 case 4:
1340 term.mode &= ~MODE_INSERT;
1341 break;
1342 default:
1343 goto unknown;
1344 }
1345 }
1346 break; 1369 break;
1347 case 'M': /* DL -- Delete <n> lines */ 1370 case 'M': /* DL -- Delete <n> lines */
1348 DEFAULT(csiescseq.arg[0], 1); 1371 DEFAULT(csiescseq.arg[0], 1);
@@ -1366,58 +1389,7 @@ csihandle(void) {
1366 tmoveto(term.c.x, csiescseq.arg[0]-1); 1389 tmoveto(term.c.x, csiescseq.arg[0]-1);
1367 break; 1390 break;
1368 case 'h': /* SM -- Set terminal mode */ 1391 case 'h': /* SM -- Set terminal mode */
1369 if(csiescseq.priv) { 1392 tsetmode(csiescseq.priv, 1, csiescseq.arg, csiescseq.narg);
1370 switch(csiescseq.arg[0]) {
1371 case 1:
1372 term.mode |= MODE_APPKEYPAD;
1373 break;
1374 case 5: /* DECSCNM -- Reverve video */
1375 if(!IS_SET(MODE_REVERSE)) {
1376 term.mode |= MODE_REVERSE;
1377 draw();
1378 }
1379 break;
1380 case 7:
1381 term.mode |= MODE_WRAP;
1382 break;
1383 case 20:
1384 term.mode |= MODE_CRLF;
1385 break;
1386 case 12: /* att610 -- Start blinking cursor (IGNORED) */
1387 /* fallthrough for xterm cvvis = CSI [ ? 12 ; 25 h */
1388 if(csiescseq.narg > 1 && csiescseq.arg[1] != 25)
1389 break;
1390 case 25:
1391 term.c.state &= ~CURSOR_HIDE;
1392 break;
1393 case 1000: /* 1000,1002: enable xterm mouse report */
1394 term.mode |= MODE_MOUSEBTN;
1395 break;
1396 case 1002:
1397 term.mode |= MODE_MOUSEMOTION;
1398 break;
1399 case 1049: /* = 1047 and 1048 */
1400 case 47:
1401 case 1047:
1402 if(IS_SET(MODE_ALTSCREEN))
1403 tclearregion(0, 0, term.col-1, term.row-1);
1404 else
1405 tswapscreen();
1406 if(csiescseq.arg[0] != 1049)
1407 break;
1408 case 1048:
1409 tcursor(CURSOR_SAVE);
1410 break;
1411 default: goto unknown;
1412 }
1413 } else {
1414 switch(csiescseq.arg[0]) {
1415 case 4:
1416 term.mode |= MODE_INSERT;
1417 break;
1418 default: goto unknown;
1419 }
1420 };
1421 break; 1393 break;
1422 case 'm': /* SGR -- Terminal attribute (color) */ 1394 case 'm': /* SGR -- Terminal attribute (color) */
1423 tsetattr(csiescseq.arg, csiescseq.narg); 1395 tsetattr(csiescseq.arg, csiescseq.narg);