From a64ca9d14f8c197398badad39148b794757742b2 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 22 Jul 2019 18:14:51 +0100 Subject: fix bug in screen init --- gramscii.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'gramscii.c') diff --git a/gramscii.c b/gramscii.c index 1223a76..24841f3 100644 --- a/gramscii.c +++ b/gramscii.c @@ -51,6 +51,8 @@ #define MIN(x,y) (x) < (y) ? (x) : (y) #define MAX(x,y) (x) > (y) ? (x) : (y) +#define DEBUG 1 + char **screen; int WIDTH, HEIGHT; @@ -129,6 +131,9 @@ void status_bar(){ printf(" [%s]", fname ); else printf(" *%s*", fname ); +#ifdef DEBUG + printf(" '%d' ", screen[y][x]); +#endif printf("\033[0m"); } @@ -168,7 +173,7 @@ void show_cursor(){ printf("\033[%d;%df", y+1, x+1); } -void set(char c){ +void set_cur(char c){ screen[y][x] = c; } @@ -190,7 +195,8 @@ void update_current(){ void erase_line(char *s){ while(*s){ - *s++ = BG; + *s = BG; + s++; } } @@ -214,7 +220,6 @@ void erase_screen(){ erase_line(screen[i]); } - void check_bound(){ if (x<0) x=0; else if (x>=WIDTH) x = WIDTH-1; @@ -232,10 +237,8 @@ void reset_styles(){ line_v = vlines[cur_vl]; mark_st = st_marks[cur_start]; mark_end = end_marks[cur_end]; - } - void redraw(){ int i; @@ -302,7 +305,6 @@ void handle_goto(){ show_cursor(); } - int move_around(char c){ switch(c){ @@ -421,12 +423,12 @@ void get_text(){ redraw(); while((c=getchar())!=EOF && c != 27){ if(c=='\n'){ - set(BG); + set_cur(BG); y += 1; x = orig_x; } else { - set(c); + set_cur(c); update_current(); modified = 1; x += 1; @@ -735,18 +737,26 @@ void init_screen(){ struct winsize wsz; if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz)){ - WIDTH=wsz.ws_col; + WIDTH=wsz.ws_col - 2; HEIGHT=wsz.ws_row - 1; } else { - WIDTH=8; + WIDTH=80; HEIGHT=24; } screen = malloc(HEIGHT * sizeof(char *)); + if (screen == NULL){ + perror("allocating screen"); + exit(1); + } for (i=0; i