diff options
| author | Karl Schultheisz <kdsch@protonmail.com> | 2020-01-21 21:27:11 -0500 |
|---|---|---|
| committer | Karl Schultheisz <kdsch@protonmail.com> | 2020-01-21 21:27:11 -0500 |
| commit | 2d6150426fe825cd7b179c5c3ed648ae607be122 (patch) | |
| tree | 72d0d8be0c235900736ef0b89fe4770d98c5e1c9 /vis-menu.c | |
| parent | cb03746137bc23f3c1b485088fefb9d4feffa368 (diff) | |
| parent | 30cd60cc2b2babda36ab752396df58697e9f26fd (diff) | |
| download | vis-2d6150426fe825cd7b179c5c3ed648ae607be122.tar.gz vis-2d6150426fe825cd7b179c5c3ed648ae607be122.tar.xz | |
Merge branch 'master' into add-layout-option
Diffstat (limited to 'vis-menu.c')
| -rw-r--r-- | vis-menu.c | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -41,6 +41,7 @@ #include <sys/types.h> #include <termios.h> #include <unistd.h> +#include <errno.h> #define CONTROL(ch) (ch ^ 0x40) #define MIN(a,b) ((a) < (b) ? (a) : (b)) @@ -59,9 +60,9 @@ struct Item { static char text[BUFSIZ] = ""; static int barpos = 0; -static int mw, mh; -static int lines = 0; -static int inputw, promptw; +static size_t mw, mh; +static size_t lines = 0; +static size_t inputw, promptw; static size_t cursor; static char *prompt = NULL; static Item *items = NULL; @@ -96,7 +97,7 @@ textw(const char *s) { static void calcoffsets(void) { - int i, n; + size_t i, n; if (lines > 0) n = lines; @@ -128,7 +129,7 @@ die(const char *s) { static void drawtext(const char *t, size_t w, Color col) { const char *prestr, *poststr; - int i, tw; + size_t i, tw; char *buf; if (w<5) return; /* This is the minimum size needed to write a label: 1 char + 4 padding spaces */ @@ -156,14 +157,14 @@ drawtext(const char *t, size_t w, Color col) { static void resetline(void) { - if (barpos != 0) fprintf(stderr, "\033[%iH", barpos > 0 ? 0 : (mh-lines)); - else fprintf(stderr, "\033[%iF", lines); + if (barpos != 0) fprintf(stderr, "\033[%ldH", (long)(barpos > 0 ? 0 : (mh-lines))); + else fprintf(stderr, "\033[%zuF", lines); } static void drawmenu(void) { Item *item; - int rw; + size_t rw; /* use default colors */ fprintf(stderr, "\033[0m"); @@ -195,12 +196,12 @@ drawmenu(void) { if ((rw -= textw(item->text)) <= 0) break; } if (next) { - fprintf(stderr, "\033[%iG", mw-5); + fprintf(stderr, "\033[%zuG", mw-5); drawtext(">", 5 /*textw(">")*/, C_Normal); } } - fprintf(stderr, "\033[%iG", (int)(promptw+textwn(text, cursor)-1)); + fprintf(stderr, "\033[%ldG", (long)(promptw+textwn(text, cursor)-1)); fflush(stderr); } @@ -591,7 +592,10 @@ main(int argc, char **argv) { if (prompt && !prompt[0]) prompt = NULL; } else if (!strcmp(argv[i], "-l")) { - lines = atoi(argv[++i]); + errno = 0; + lines = strtoul(argv[++i], NULL, 10); + if (errno) + usage(); } else { usage(); } |
