diff --git a/build/resize b/build/resize new file mode 100755 index 0000000..50d960c Binary files /dev/null and b/build/resize differ diff --git a/build_resize.sh b/build_resize.sh new file mode 100755 index 0000000..34952dd --- /dev/null +++ b/build_resize.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +code="$PWD" +opts="-g -Wno-switch" + +mkdir -p build +cd build +echo resize +clang $opts $code/src/resize.main.c -lncurses -o resize diff --git a/project.4coder b/project.4coder index 54dc483..d46b769 100644 --- a/project.4coder +++ b/project.4coder @@ -30,9 +30,13 @@ commands = { .build_colors = { .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .win = "build_colors.bat", .linux = "./build_colors.sh", .mac = "./build_colors.sh", }, + + .build_resize = { .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, + .win = "build_resize.bat", .linux = "./build_resize.sh", .mac = "./build_resize.sh", }, }; fkey_command = { .F1 = "build_printinput", .F2 = "build_animate", .F3 = "build_colors", +.F4 = "build_resize", }; diff --git a/src/resize.main.c b/src/resize.main.c new file mode 100644 index 0000000..217a54d --- /dev/null +++ b/src/resize.main.c @@ -0,0 +1,97 @@ +#include "mr4th/mr4th_base.h" +#include + +#include "mr4th/mr4th_base.c" + +int main(){ + // initializes ncurses + initscr(); + + // settings + noecho(); + cbreak(); + + // get size + int window_x = 0; + int window_y = 0; + getmaxyx(stdscr, window_y, window_x); + + + { + clear(); + + // size & corners + move(0, 0); + printw("SIZE: %d, %d", window_x, window_y); + if (window_y > 2){ + mvaddch(window_y - 1, 0, '#'); + mvaddch(window_y - 1, window_x - 1, '#'); + } + mvaddch(0, window_x - 1, '#'); + + refresh(); + } + + // program + int y_counter = 0; + for (;;){ + int c = getch(); + + // apply resize + if (c == KEY_RESIZE){ + getmaxyx(stdscr, window_y, window_x); + } + + clear(); + + // size & corners + move(0, 0); + printw("SIZE: %d, %d", window_x, window_y); + if (window_y > 2){ + mvaddch(window_y - 1, 0, '#'); + mvaddch(window_y - 1, window_x - 1, '#'); + } + mvaddch(0, window_x - 1, '#'); + + // (27 '^[' ESC) + move(1, 0); + if (c == 27){ + printw("ESC "); + + // read escape bytes + nodelay(stdscr, 1); + int bcount = 0; + char b[10]; + for (;;){ + char bx = getch(); + if (bx == ERR){ + break; + } + if (bcount < 10){ + b[bcount] = bx; + } + bcount += 1; + } + nodelay(stdscr, 0); + + // print escape + int bcount_clamped = Min(10, bcount); + for (int i = 0; i < bcount_clamped; i += 1){ + printw("%u ", b[i]); + } + if (bcount_clamped < bcount){ + printw("... (%u more), ", bcount - bcount_clamped); + } + } + else{ + printw("'%c' [%u]", c, c); + } + + refresh(); + } + + // end ncurses + endwin(); + + return(0); +}