Something went wrong. Try again.
a less like pager but for fun
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186#include "shared.h"#include <ncurses.h>#include <sys/param.h>
#include "draw.h"
void handle_key(WINDOW *win, context c, context hp) {
FILE *tty = fopen("/dev/tty", "r"); if (tty == NULL) FATAL("could not open /dev/tty")
context* ctx = &c; char k; char m;
while((k = getc(tty))){
populate_w_data(ctx, win);
if (ctx == &c) ctx->help = NONE;
switch (k) {
/// META IDK
case 'q': case 'Q': case 0x1b: // ESC if (ctx == &hp) { ctx = &c; draw(ctx, win); break; } else return; case 'h': case 'H': if (ctx == &c) ctx = &hp; else ctx = &c; draw(ctx, win); break; case 'r': case 'R': draw(ctx, win); break;
/// MOVING
case 'j': case 'e': case 0x05: // ^E case 0x0d: // CR move_vertical_and_draw(ctx, win, 1); break; case 'k': case 'y': case 0x19: // ^Y move_vertical_and_draw(ctx, win, -1); break; case 'd': case 0x04: // ^D move_vertical_and_draw(ctx, win, ctx->w.half_window); break; case 'u': case 0x15: // ^U move_vertical_and_draw(ctx, win, -ctx->w.half_window); break; case 'z': move_vertical_and_draw(ctx, win, ctx->w.window); break; case 'w': move_vertical_and_draw(ctx, win, -ctx->w.window); break; case ']': case ')': move_horizontal_and_draw(ctx, win, ctx->w.half_width); break; case '[': case '(': case '*': move_horizontal_and_draw(ctx, win, -ctx->w.half_width); break; case '}': move_horizontal_and_draw(ctx, win, ctx->w.width); break; case '{': move_horizontal_and_draw(ctx, win, -ctx->w.width); break;
/// JUMPING
case 'g': set_line(ctx, 0); draw(ctx, win); break; case 'G': set_line(ctx, ctx->size - ctx->w.window); draw(ctx, win); break; case '$': case 'A': // TODO: get line length set_xoffset(ctx, 999); draw(ctx, win); break; case '0': case 'I': case '_': set_xoffset(ctx, 0); draw(ctx, win); break;
/// MARKING
// set mark case 'm': m = await_input(ctx, win, tty, 'a'); // at the top set_mark(ctx, m, ctx->line); draw(ctx, win); break; case 'M': m = await_input(ctx, win, tty, 'a'); // at the bottom set_mark(ctx, m, MIN(ctx->size, ctx->line + ctx->w.window - 1)); draw(ctx, win); break; // goto mark case '\'': m = await_input(ctx, win, tty, 'a'); // at the top set_line(ctx, ctx->marks[m - REG_START] - 1); draw(ctx, win); break; case '"': m = await_input(ctx, win, tty, 'a'); // at the bottom set_line(ctx, ctx->marks[m - REG_START] - ctx->w.window); draw(ctx, win); break;
/// GIT STUFF // case 'p': // for (int i = ctx->line + 1; i < ctx->size; i++) { // if (strncmp(strip_ansi(ctx->content[i]), "@@", 2) == 0) { // ctx->line = i; // draw(ctx, win); // break; // } // } // break; // case 'P': // for (int i = ctx->line - 1; i > -1; i--) { // if (strncmp(strip_ansi(ctx->content[i]), "@@", 2) == 0) { // ctx->line = i; // draw(ctx, win); // break; // } // } // break; // case 'l': // for (int i = ctx->line + 1; i < ctx->size; i++) { // if (strncmp(strip_ansi(ctx->content[i]), "commit", 6) == 0) { // ctx->line = i; // draw(ctx, win); // break; // } // } // break; // case 'L': // for (int i = ctx->line - 1; i > -1; i--) { // if (strncmp(strip_ansi(ctx->content[i]), "commit", 6) == 0) { // ctx->line = i; // draw(ctx, win); // break; // } // } // break;
default: if (ctx == &c) ctx->help = STATUS; draw_status(ctx, win, false); refresh(); break; } }}