aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Aptel <aurelien.aptel@gmail.com>2010-08-27 00:28:27 +0200
committerAurélien Aptel <aurelien.aptel@gmail.com>2010-08-27 00:28:27 +0200
commitfbb66da9a9ef3c12c1e8dee7433d003b85d70e9c (patch)
tree30bddbc51a63895add33d349c27271280fc329c5
parent42b2912e2151f02e181bd014ce1610f7e03a7d07 (diff)
downloadst-fbb66da9a9ef3c12c1e8dee7433d003b85d70e9c.tar.gz
st-fbb66da9a9ef3c12c1e8dee7433d003b85d70e9c.zip
merged tcursorwrap() with tnewline(), added few comments and updated copyright.
-rw-r--r--st.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/st.c b/st.c
index 9667dbd..ebe896c 100644
--- a/st.c
+++ b/st.c
@@ -129,7 +129,6 @@ static void csireset(void);
129 129
130static void tclearregion(int, int, int, int); 130static void tclearregion(int, int, int, int);
131static void tcursor(int); 131static void tcursor(int);
132static void twrapcursor(void);
133static void tdeletechar(int); 132static void tdeletechar(int);
134static void tdeleteline(int); 133static void tdeleteline(int);
135static void tinsertblank(int); 134static void tinsertblank(int);
@@ -337,7 +336,8 @@ treset(void) {
337} 336}
338 337
339void 338void
340tnew(int col, int row) { /* screen size */ 339tnew(int col, int row) {
340 /* screen size */
341 term.row = row, term.col = col; 341 term.row = row, term.col = col;
342 term.top = 0, term.bot = term.row - 1; 342 term.top = 0, term.bot = term.row - 1;
343 /* mode */ 343 /* mode */
@@ -438,16 +438,6 @@ tmoveto(int x, int y) {
438} 438}
439 439
440void 440void
441twrapcursor(void) {
442 int y = term.c.y+1;
443 if(y > term.bot) {
444 tmoveto(0, term.bot);
445 tscroll();
446 } else
447 tmoveto(0, y);
448}
449
450void
451tsetchar(char c) { 441tsetchar(char c) {
452 term.line[term.c.y][term.c.x] = term.c.attr; 442 term.line[term.c.y][term.c.x] = term.c.attr;
453 term.line[term.c.y][term.c.x].c = c; 443 term.line[term.c.y][term.c.x].c = c;
@@ -974,7 +964,7 @@ tputc(char c) {
974 if(term.c.x+1 < term.col) { 964 if(term.c.x+1 < term.col) {
975 tmoveto(term.c.x+1, term.c.y); 965 tmoveto(term.c.x+1, term.c.y);
976 } else if(IS_SET(MODE_WRAP)) 966 } else if(IS_SET(MODE_WRAP))
977 twrapcursor(); 967 tnewline();
978 break; 968 break;
979 } 969 }
980 } 970 }
@@ -995,13 +985,20 @@ tresize(int col, int row) {
995 if(col < 1 || row < 1) 985 if(col < 1 || row < 1)
996 return; 986 return;
997 987
988 /* free uneeded rows */
998 for(i = row; i < term.row; i++) 989 for(i = row; i < term.row; i++)
999 free(term.line[i]); 990 free(term.line[i]);
991
992 /* resize to new height */
1000 term.line = realloc(term.line, row * sizeof(Line)); 993 term.line = realloc(term.line, row * sizeof(Line));
994
995 /* resize each row to new width, zero-pad if needed */
1001 for(i = 0; i < minrow; i++) { 996 for(i = 0; i < minrow; i++) {
1002 term.line[i] = realloc(term.line[i], col * sizeof(Glyph)); 997 term.line[i] = realloc(term.line[i], col * sizeof(Glyph));
1003 memset(term.line[i] + mincol, 0, (col - mincol) * sizeof(Glyph)); 998 memset(term.line[i] + mincol, 0, (col - mincol) * sizeof(Glyph));
1004 } 999 }
1000
1001 /* allocate any new rows */
1005 for(/* i == minrow */; i < row; i++) 1002 for(/* i == minrow */; i < row; i++)
1006 term.line[i] = calloc(col, sizeof(Glyph)); 1003 term.line[i] = calloc(col, sizeof(Glyph));
1007 1004
@@ -1337,7 +1334,7 @@ run(void) {
1337int 1334int
1338main(int argc, char *argv[]) { 1335main(int argc, char *argv[]) {
1339 if(argc == 2 && !strncmp("-v", argv[1], 3)) 1336 if(argc == 2 && !strncmp("-v", argv[1], 3))
1340 die("st-" VERSION ", © 2009 st engineers\n"); 1337 die("st-" VERSION ", (c) 2010 st engineers\n");
1341 else if(argc != 1) 1338 else if(argc != 1)
1342 die("usage: st [-v]\n"); 1339 die("usage: st [-v]\n");
1343 setlocale(LC_CTYPE, ""); 1340 setlocale(LC_CTYPE, "");