Merge branch 'master' of bitbucket.org:spilt/bb
This commit is contained in:
commit
634a8517b1
31
bb.c
31
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;
|
||||
}
|
||||
|
||||
|
7
bterm.h
7
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user