aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-06-18 17:02:17 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-06-18 17:02:17 -0700
commit634a8517b14d313291605e8761a2e0a740d990a0 (patch)
tree89d9051380b518f0e509f687b07bf84ef4e8306b
parente09bb2d3edcb5fbb6e41bac24282d573e8e5c6a5 (diff)
parentb86066b46aa19612aa0ca991aa2321d86d11b718 (diff)
Merge branch 'master' of bitbucket.org:spilt/bb
-rw-r--r--bb.c31
-rw-r--r--bterm.h7
2 files changed, 20 insertions, 18 deletions
diff --git a/bb.c b/bb.c
index fac8a4c..8cf9fd9 100644
--- a/bb.c
+++ b/bb.c
@@ -6,6 +6,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
+#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
@@ -40,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
@@ -184,13 +185,17 @@ 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;
- 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);
@@ -411,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;
}
@@ -663,15 +668,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);
}
}
@@ -684,8 +689,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;
}
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 <poll.h>
#include <stdio.h>
#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;
}
/*