From 8d5e68d4441228b0c101940a9b7189938e755130 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 17 Jun 2019 14:52:38 -0700 Subject: Fix for term attrs getting messed up by Fish shell --- bb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bb.c b/bb.c index a4f3d7b..8aed841 100644 --- a/bb.c +++ b/bb.c @@ -187,9 +187,13 @@ void update_term_size(int sig) */ void init_term(void) { + static int first_time = 1; tty_in = fopen("/dev/tty", "r"); tty_out = fopen("/dev/tty", "w"); - tcgetattr(fileno(tty_out), &orig_termios); + if (first_time) { + tcgetattr(fileno(tty_out), &orig_termios); + first_time = 0; + } memcpy(&bb_termios, &orig_termios, sizeof(bb_termios)); cfmakeraw(&bb_termios); bb_termios.c_cc[VMIN] = 0; -- cgit v1.2.3 From fbfe8689a83884c88518b22f0b5bb2dbf453e408 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 17 Jun 2019 16:45:24 -0700 Subject: Changing IO code to no longer use poll() in favor of just reading input and using VMIN and VTIME. --- bb.c | 5 +++-- bterm.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/bb.c b/bb.c index 8aed841..6e04403 100644 --- a/bb.c +++ b/bb.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -196,8 +197,8 @@ void init_term(void) } memcpy(&bb_termios, &orig_termios, sizeof(bb_termios)); cfmakeraw(&bb_termios); - bb_termios.c_cc[VMIN] = 0; - bb_termios.c_cc[VTIME] = 0; + bb_termios.c_cc[VMIN] = 1; + bb_termios.c_cc[VTIME] = 1; if (tcsetattr(fileno(tty_out), TCSAFLUSH, &bb_termios) == -1) err("Couldn't tcsetattr"); update_term_size(0); diff --git a/bterm.h b/bterm.h index dbade7a..c233c84 100644 --- a/bterm.h +++ b/bterm.h @@ -10,7 +10,6 @@ #ifndef FILE__BTERM_H #define FILE__BTERM_H -#include #include #define KEY_F1 (0xFFFF-0) @@ -112,11 +111,9 @@ const char *bkeyname(int key); static inline int nextchar(int fd, int timeout) { + (void)timeout; char c; - struct pollfd pfd = {fd, POLLIN, 0}; - if (poll(&pfd, 1, timeout) > 0) - return read(fd, &c, 1) == 1 ? c : -1; - return -1; + return read(fd, &c, 1) == 1 ? c : -1; } /* -- cgit v1.2.3 From c9343baf154e1201ed35312be5753853ca336f8f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 17 Jun 2019 16:50:03 -0700 Subject: Fixed onscreen off-by-one error --- bb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bb.c b/bb.c index 6e04403..7302ceb 100644 --- a/bb.c +++ b/bb.c @@ -41,7 +41,7 @@ #define IS_VIEWED(p) ((p)->index >= 0) #define LOWERCASE(c) ('A' <= (c) && (c) <= 'Z' ? ((c) + 'a' - 'A') : (c)) #define E_ISDIR(e) (S_ISDIR(S_ISLNK((e)->info.st_mode) ? (e)->linkedmode : (e)->info.st_mode)) -#define ONSCREEN (termheight - 4) +#define ONSCREEN (termheight - 3) #ifdef __APPLE__ #define mtime(s) (s).st_mtimespec @@ -416,11 +416,11 @@ void render(bb_t *bb) } entry_t **files = bb->files; - for (int i = bb->scroll; i < bb->scroll + termheight - 3; i++) { + for (int i = bb->scroll; i < bb->scroll + ONSCREEN; i++) { if (!bb->dirty) { if (i == bb->cursor || i == lastcursor) goto do_render; - if (i < lastscroll || i >= lastscroll + termheight - 3) + if (i < lastscroll || i >= lastscroll + ONSCREEN) goto do_render; continue; } @@ -697,15 +697,15 @@ void set_cursor(bb_t *bb, int newcur) if (oldcur < bb->cursor) { if (bb->scroll > bb->cursor) bb->scroll = MAX(0, bb->cursor); - else if (bb->scroll < bb->cursor - ONSCREEN + SCROLLOFF) - bb->scroll = MIN(bb->nfiles - 1 - ONSCREEN, + else if (bb->scroll < bb->cursor - ONSCREEN + 1 + SCROLLOFF) + bb->scroll = MIN(bb->nfiles - 1 - ONSCREEN + 1, bb->scroll + (newcur - oldcur)); } else { if (bb->scroll > bb->cursor - SCROLLOFF) bb->scroll = MAX(0, bb->scroll + (newcur - oldcur));//bb->cursor - SCROLLOFF); - else if (bb->scroll < bb->cursor - ONSCREEN) - bb->scroll = MIN(bb->cursor - ONSCREEN, - bb->nfiles - 1 - ONSCREEN); + else if (bb->scroll < bb->cursor - ONSCREEN + 1) + bb->scroll = MIN(bb->cursor - ONSCREEN + 1, + bb->nfiles - 1 - ONSCREEN + 1); } } @@ -718,8 +718,8 @@ void set_scroll(bb_t *bb, int newscroll) if (bb->nfiles <= ONSCREEN) { newscroll = 0; } else { - if (newscroll > bb->nfiles - 1 - ONSCREEN) - newscroll = bb->nfiles - 1 - ONSCREEN; + if (newscroll > bb->nfiles - 1 - ONSCREEN + 1) + newscroll = bb->nfiles - 1 - ONSCREEN + 1; if (newscroll < 0) newscroll = 0; } -- cgit v1.2.3