diff options
author | KatolaZ <katolaz@freaknet.org> | 2019-07-27 08:31:24 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2019-07-27 08:31:24 +0100 |
commit | a99759398841d86928c7ad4d8248f907765cbeb2 (patch) | |
tree | 5adb05a273e0532be2665e8ae95a8b4042809213 | |
parent | b38ed132a7df231fc08ce384d8559e6648fdd0cc (diff) |
add crop-to-visible function (C)
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | config.mk | 2 | ||||
-rw-r--r-- | draw.c | 1 | ||||
-rw-r--r-- | gramscii.1 | 5 | ||||
-rw-r--r-- | gramscii.h | 1 | ||||
-rw-r--r-- | screen.c | 30 |
6 files changed, 36 insertions, 5 deletions
@@ -1,5 +1,4 @@ + optimize redraws (redraw only the modified rectangle) -+ add crop command (C) - fix bug with 'g' commands in arrow mode - add screen geometry option (-g 25x80?) - read file at point @@ -25,6 +24,7 @@ - allow scrolling (both vertical and horizontal) - catch SIGWINCH and react appropriately (after scrolling is enabled) +* add crop command (C) * reorganise code * change screen management (i.e., dynamic array of lines) * add action multiplier (e.g., "7h" moves left by 7 cols) @@ -2,5 +2,5 @@ PREFIX = /usr/local BINDIR = ${PREFIX}/bin MANDIR = ${PREFIX}/share/man -CFLAGS = -O3 -std=c90 -pedantic -Wall +CFLAGS = -O0 -std=c99 -pedantic -Wall CC = cc @@ -303,6 +303,7 @@ void visual_box(FILE *fc){ f = get_key(fc, "fill char: "); /** FALLTHROUGH **/ case 'x':/* erase */ erase_box(orig_x, orig_y, f); + erase_blank_lines(MIN(y,orig_y), MAX(y, orig_y)); modified = 1; goto vis_exit; break; @@ -52,6 +52,11 @@ mode: .BI R Redraw the screen .TP 5m +.BI C +Crop chart to the largest non-blank region. The first line and the first +column of the cropped chart will contain the first non-blank line and +the first non-blank column of the original chart, respectively. +.TP 5m .BI q Quit gramscii, and prompt for a filename if the current screen contains unsaved changes. @@ -120,6 +120,7 @@ void erase_line(int i); void erase_screen(); void go_to(int where); void crop_to_nonblank(); +void erase_blank_lines(int y1, int y2); /** drawing-related functions **/ int change_style(char c); @@ -197,6 +197,26 @@ void update_current(){ fflush(stdout); } +void erase_blank_lines(int y1, int y2){ + int j; + if (y1 > y2){ + y1 ^= y2; + y2 ^= y1; + y1 ^= y2; + } + + for (; y1 <= y2; y1++){ + j = screen[y1].lst; + while (j>=0 && isblank(screen[y1].s[j])) + j--; + if (j<0){ + screen[y1].lst = -1; + screen[y1].s[0] = '\0'; + } + } +} + + void erase_line(int i){ screen[i].lst = -1; screen[i].s[0] = '\0'; @@ -446,13 +466,16 @@ void find_nonblank_rect(int *x1, int *y1, int *x2, int *y2){ *y2 = i; if (i < *y1) *y1 = i; - if (screen[i].lst > *x2) - *x2 = screen[i].lst; j = 0; - while(j <= screen[i].lst && isblank(first=screen[i].s[j])) + while((j <= screen[i].lst) && isblank(first=screen[i].s[j])) j++; if (j < *x1) *x1 = j; + j = screen[i].lst; + while(isblank(screen[i].s[j])) + j--; + if (j > *x2) + *x2 = j; } } @@ -478,6 +501,7 @@ void crop_to_nonblank(){ fprintf(stderr, "crop rectangle: (%d, %d)-(%d, %d)\n", x1, y1, x2, y2); #endif crop_to_rect(x1, y1, x2, y2); + modified=1; redraw(); } |