Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

commit b1e7f4eebb4fd8d5f6c77dcdf240b16ca115e2a4 Author: rani <clagv.randomgames@gmail.com> Date: Sat Jan 28 21:34:02 2023 +0000 Added info buffer viewer diff --git a/include/io.h b/include/io.h index dda0f0c..1202402 100644 --- a/include/io.h +++ b/include/io.h @@ -216 +2127 @@  #define ANSI_RESET ESC "[0m"     +#define UP_KEYS \ + KEY_UP: \ + case CTRL_P: \ + case 'k' + +#define DOWN_KEYS \ + KEY_DOWN: \ + case CTRL_N: \ + case 'j' + +#define LEFT_KEYS \ + KEY_LEFT: \ + case CTRL_B: \ + case 'h' + +#define RIGHT_KEYS \ + KEY_RIGHT: \ + case CTRL_F: \ + case 'l' + +  enum colors {   COLOR_DIR = 1,   COLOR_LINK = 2, @@ -936 +1147 @@ char * get_gname(gid_t);  void info_init(void);  void display_info(enum info_t, char *);  void refresh_info(void); +int get_info_color(struct info_node *);      extern bool print_path; diff --git a/src/io.c b/src/io.c index d599c64..5c159e0 100644 --- a/src/io.c +++ b/src/io.c @@ -34620 +34612 @@ char * prompt(char * t, char ** args) {     int c = getch();   switch (c) { - case KEY_UP: - case KEY_LEFT: - case CTRL_P: - case CTRL_B: - case 'h': - case 'k': + case UP_KEYS: + case LEFT_KEYS:   if (cursor > 1) cursor--;   break; - case KEY_DOWN: - case KEY_RIGHT: - case CTRL_N: - case CTRL_F: - case 'l': - case 'j': + case DOWN_KEYS: + case RIGHT_KEYS:   if ((unsigned)cursor < argcount) cursor++;   break;   case '\n': @@ -82318 +81523 @@ void display_info(enum info_t type, char * msg) {  }     +int get_info_color(struct info_node * n) { + switch (n->type) { + default: + case INFO_INFO: return COLOR_PAIR(WHITE); + case INFO_WARN: return COLOR_PAIR(YELLOW) | A_REVERSE; + case INFO_ERR: return COLOR_PAIR(RED) | A_REVERSE; + } +} + +  void refresh_info(void) {   if (info_buffer.n == 0 || !info_buffer.w) return;     size_t n = info_buffer.n - 1;   - int cp = 0; - switch (info_buffer.i[n]->type) { - case INFO_INFO: cp = COLOR_PAIR(WHITE); break; - case INFO_WARN: cp = COLOR_PAIR(YELLOW) | A_REVERSE; break; - case INFO_ERR: cp = COLOR_PAIR(RED) | A_REVERSE; break; - }   + int cp = get_info_color(info_buffer.i[n]);   werase(info_buffer.w);   waddstr(info_buffer.w, "(:i) ");   wattron(info_buffer.w, cp); @@ -8423 +83961 @@ void refresh_info(void) {   wattroff(info_buffer.w, cp);   wrefresh(info_buffer.w);  } + + +void page_info() { + if (info_buffer.n == 0 || !info_buffer.w) return; + + clear(); + + size_t first_info = 0; + size_t last_info = info_buffer.n - 1; + if (last_info >= (unsigned)LINES - 1) last_info = LINES - 1; + + bool done = false; + + while (!done) { + erase(); + + for (size_t i = first_info; i < last_info; i++) { + int cp = get_info_color(info_buffer.i[i]); + attron(cp); + addstr(info_buffer.i[i]->msg); + attroff(cp); + addch('\n'); + } + + printw("LINES %lu-%lu/%lu, q to close\n", + first_info + 1, last_info, info_buffer.n); + + refresh(); + + int c = getch(); + switch (c) { + case UP_KEYS: + if (first_info > 0) { + first_info--; + last_info--; + } + break; + case DOWN_KEYS: + if (last_info < info_buffer.n) { + first_info++; + last_info++; + } + break; + case KEY_RESIZE: + // jump back to the top, it is fine. + first_info = 0; + last_info = info_buffer.n - 1; + if (last_info >= (unsigned)LINES - 1) last_info = LINES - 1; + // make sure the file buffer is resized too + resize_fbuf(); + break; + case CTRL_C: + case 'q': + done = true; + break; + } + } +} diff --git a/src/main.c b/src/main.c index 5222db4..853803d 100644 --- a/src/main.c +++ b/src/main.c @@ -21919 +21913 @@ int main(int argc, char ** argv) {     int c = getch();   switch (c) { - case KEY_UP: - case CTRL_P: - case 'k': + case UP_KEYS:   if (cursor > 1) cursor--;   break; - case KEY_DOWN: - case CTRL_N: - case 'j': + case DOWN_KEYS:   if (cursor < n_dir_entries) cursor++;   break; - case KEY_LEFT: - case CTRL_B: - case 'h':; + case LEFT_KEYS:   // can't cd back when in /   if (cwd[0] == '/' && cwd[1] == '\0') break;   @@ -2549 +2487 @@ int main(int argc, char ** argv) {     free(cur_dir);   break; - case KEY_RIGHT: - case CTRL_F: - case 'l': + case RIGHT_KEYS:   case '\n':   if (!n_dir_entries) break;   open_cur_file(); @@ -4446 +4368 @@ int main(int argc, char ** argv) {   } else if (!strcmp(inp, "ca") && !cutting) {   mark_all();   create_cuts(cwd, NULL); + } else if (!strcmp(inp, "i")) { + page_info();   }   free(inp);   break;