URI: 
       initial commit of dynamic screen size - gramscii - A simple editor for ASCII box-and-arrow charts
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit c9a6b0faecb76984eb51754f6d188a87be025e8f
   DIR parent 0325743daff41b74466fb198eee5774d0c2ac004
  HTML Author: KatolaZ <katolaz@freaknet.org>
       Date:   Mon, 22 Jul 2019 17:05:57 +0100
       
       initial commit of dynamic screen size
       
       Diffstat:
         M gramscii.c                          |      50 ++++++++++++++++++++-----------
       
       1 file changed, 32 insertions(+), 18 deletions(-)
       ---
   DIR diff --git a/gramscii.c b/gramscii.c
       @@ -10,6 +10,7 @@
        #include <unistd.h>
        #include <signal.h>
        #include <string.h>
       +#include <sys/ioctl.h>
        
        #define MOVE   0x00
        #define BOX    0x01
       @@ -27,8 +28,6 @@
        #define DIR_HOR (DIR_R | DIR_L)
        #define DIR_VER (DIR_D | DIR_U)
        
       -#define WIDTH  100
       -#define HEIGHT  25
        
        #define NOFIX 0x0
        #define FIX   0x1
       @@ -52,7 +51,8 @@
        #define MIN(x,y)  (x) < (y) ? (x) : (y)
        #define MAX(x,y)  (x) > (y) ? (x) : (y)
        
       -char screen[HEIGHT][WIDTH+1];
       +char **screen;
       +int WIDTH, HEIGHT;
        
        int state;
        int dir;
       @@ -121,7 +121,7 @@ char* state_str(){
        void status_bar(){
        
                printf("\033[%d;1f\033[7m", HEIGHT+1);
       -        printf("%100s", " ");
       +        printf("%*s", WIDTH-1, "");
                printf("\033[%d;1f\033[7m", HEIGHT+1);
                printf(" x:%3d y:%3d -- MODE:%4s HL:%c VL:%c CN:%c SP:%c EP:%c %10s",
                        x, y, state_str(), line_h, line_v, corner, mark_st, mark_end, "");
       @@ -132,12 +132,12 @@ void status_bar(){
                printf("\033[0m");
        }
        
       -char get_key(char *s){
       +char get_key(char *msg){
        
                printf("\033[%d;1f\033[7m", HEIGHT+1);
       -        printf("%100s", " ");
       +        printf("%*s", WIDTH, "");
                printf("\033[%d;1f\033[7m", HEIGHT+1);
       -        printf("%s ", s);
       +        printf("%s", msg);
                printf("\033[0m");
                return getchar();
        }
       @@ -145,7 +145,7 @@ char get_key(char *s){
        void get_string(char *msg, char *s, int sz){
        
                printf("\033[%d;1f\033[7m", HEIGHT+1);
       -        printf("%100s", " ");
       +        printf("%*s", WIDTH, "");
                printf("\033[%d;1f\033[7m", HEIGHT+1);
                /* We must activate echo now */
                t3 = t2;
       @@ -235,14 +235,6 @@ void reset_styles(){
        
        }
        
       -void init_screen(){
       -        int i;
       -        for(i=0; i<HEIGHT; i++){
       -                memset(screen[i], ' ', WIDTH);
       -                screen[i][WIDTH]='\0';
       -        }
       -        reset_styles();
       -}
        
        void redraw(){
                int i;
       @@ -738,6 +730,28 @@ vis_exit:
        
        /*** Initialisation ***/
        
       +void init_screen(){
       +        int i;
       +        struct winsize wsz;
       +        
       +        if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz)){
       +                WIDTH=wsz.ws_col;
       +                HEIGHT=wsz.ws_row - 1;
       +        }
       +        else {
       +                WIDTH=8;
       +                HEIGHT=24;
       +        }
       +        screen = malloc(HEIGHT * sizeof(char *));
       +        for (i=0; i<HEIGHT; i++){
       +                screen[i] = malloc((WIDTH+1) * sizeof(char));
       +                memset(screen[i], 32, WIDTH);
       +                screen[WIDTH]='\0';
       +        }
       +        reset_styles();
       +}
       +
       +
        void init(){
        
                signal(SIGHUP, cleanup);
       @@ -751,8 +765,8 @@ void init(){
                tcsetattr(0, TCSANOW, &t2);
        
                init_screen();
       -        x = WIDTH/2;
       -        y = HEIGHT/2;
       +        x = 0;
       +        y = 0;
                modified = 0;
                fname[0] = '\0';
                redraw();