sfm

simple file manager
git clone git://git.afify.dev/sfm
Log | Files | Refs | README | LICENSE

commit 54bf24bff954b551774445c45a69a099b04e9841
parent 8fea79ffaed7e09f0c6e7663c2b37fafae615677
Author: afify <hassan@afify.dev>
Date:   Thu,  2 Jul 2020 05:34:51 +0300

[feat] ctrl u & d , update scroll view

* scroll list of files and directories (height/2) instead of 4 last
  lines
* ctrl + u move up, ctrl + d, move down:
	- configured by move_ud var in config(.def).h
* add missing function declaration findbm

Diffstat:
Mconfig.def.h | 2++
Msfm.c | 15+++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -48,6 +48,8 @@ static Rule rules[] = { {"gimp", arts, LEN(arts) }, }; +static const size_t move_ud = 10; /* ctrl U, ctrl D movement */ + /* unicode chars */ static const uint32_t u_cne = 0x2510; static const uint32_t u_cnw = 0x250C; diff --git a/sfm.c b/sfm.c @@ -79,6 +79,7 @@ static int open_files(char*); static int sort_name(const void *const, const void *const); static void float_to_string(float, char*); static int get_memory_usage(void); +static int findbm(char); static void print_col(Entry*, size_t, size_t, size_t, int, int); static int listdir(Pane*); static void press(struct tb_event*, Pane*, Pane*); @@ -710,8 +711,8 @@ listdir(Pane *cpane) /* scroll */ if (cpane->dirc > height - 1) { clear_pane(cpane->dirx); - if (cpane->hdir >= height - 4){ - i = (cpane->hdir - height) + 4; + if (cpane->hdir >= height - (height/2)){ + i = (cpane->hdir - height) + (height/2); dyn_y = i; } } @@ -819,6 +820,16 @@ press(struct tb_event *ev, Pane *cpane, Pane *opane) } else if (ev->ch == 'M') { cpane->hdir = (cpane->dirc/2); (void)listdir(cpane); + } else if (ev->key == TB_KEY_CTRL_U) { + if (cpane->hdir > move_ud) { + cpane->hdir = cpane->hdir - move_ud; + (void)listdir(cpane); + } + } else if (ev->key == TB_KEY_CTRL_D) { + if (cpane->hdir < cpane->dirc - move_ud) { + cpane->hdir = cpane->hdir + move_ud; + (void)listdir(cpane); + } } else { /* bookmarks */ b = findbm((char)ev->ch);