From 231a2b72b0b26b33c1b531b83a8cc71f1d06423a Mon Sep 17 00:00:00 2001 From: girst Date: Sun, 20 Jan 2019 19:50:19 +0100 Subject: [PATCH] automagic conserve space only when the window size would be too small to display a pile completely. still has the problem that sometimes the terminal is too small for even the extreme overlap. --- sol.c | 21 +++++++++++++++++---- sol.h | 5 ++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sol.c b/sol.c index 4b5bcf8..d35f966 100644 --- a/sol.c +++ b/sol.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -53,7 +54,6 @@ int main(int argc, char** argv) { #ifdef SPIDER op.m = MEDIUM; #endif - op.v = 0; int optget; opterr = 0; /* don't print message on unrecognized option */ @@ -68,7 +68,6 @@ int main(int argc, char** argv) { default: goto error; } break; #endif - case 'v': op.v = 1; break; /* conserve vertical space */ case 'b': op.s = &unicode_large_mono; break; case 'c': op.s = &unicode_large_color; break; case 'm': op.s = &unicode_small_mono; break; /* "mini" */ @@ -82,6 +81,8 @@ int main(int argc, char** argv) { signal_setup(); atexit (*quit); + signal_handler(SIGWINCH); /* initialize window size */ + newgame: screen_setup(1); @@ -771,7 +772,9 @@ void print_table(const struct cursor* active, const struct cursor* inactive) { :op.s->card[card] )[line[pile]]); - int extreme_overlap = op.v && find_top(f.t[pile])>10; + int extreme_overlap = ( 3 /* spacer, labels, status */ + + 2 * op.s->height /* stock, top tableu card */ + + find_top(f.t[pile]) * op.s->overlap) >op.w[0]; /* normal overlap: */ if (++line[pile] >= (next?op.s->overlap:op.s->height) /* extreme overlap on closed cards: */ @@ -980,14 +983,20 @@ void raw_mode(int enable) { } void signal_handler (int signum) { + struct winsize w; switch (signum) { case SIGCONT: screen_setup(0); screen_setup(1); print_table(NO_HI, NO_HI); break; - case SIGINT: + case SIGINT: //TODO: don't exit; just warn like vim does exit(128+SIGINT); + case SIGWINCH: + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + op.w[0] = w.ws_row; + op.w[1] = w.ws_col; + break; } } void signal_setup(void) { @@ -1004,6 +1013,10 @@ void signal_setup(void) { perror ("SIGINT"); exit (1); } + if (sigaction(SIGWINCH, &saction, NULL) < 0) { + perror ("SIGWINCH"); + exit (1); + } } //}}} diff --git a/sol.h b/sol.h index 1e2a800..9513e1d 100644 --- a/sol.h +++ b/sol.h @@ -123,7 +123,7 @@ typedef signed char card_t; struct playfield { card_t s[MAX_STOCK]; /* stock */ int z; /* stock size */ - int w; /* waste; index into stock (used foundations in spider) */ + int w; /* waste; index into stock (occupied foundations in spider) */ card_t f[NUM_DECKS*NUM_SUITS][PILE_SIZE]; /* foundation */ card_t t[NUM_PILES][PILE_SIZE]; /* tableu piles */ struct undo { @@ -140,7 +140,7 @@ struct opts { #ifdef SPIDER int m; /* difficulty mode */ #endif - int v; /* conserve vertical space */ + unsigned short w[2]; /* terminal window rows/columns */ const struct scheme* s; }; struct cursor { @@ -168,7 +168,6 @@ struct undo undo_sentinel; #define LONGHELP \ "OPTIONS:\n" \ LONGHELP_SPECIFIC \ - " -v(vertical space conserve)\n" \ " -b(land colorscheme)\n" \ " -c(olorful colorscheme)\n" \ " -m(iniature colorscheme)\n" \ -- 2.39.3