From 47996e708ad2ab7e6a18633576c95e93d08e816a Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Thu, 1 Aug 2019 08:02:33 +0100 Subject: add crop-to-region in visual mode --- draw.c | 7 +++++++ gramscii.1 | 4 ++++ gramscii.h | 3 ++- screen.c | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/draw.c b/draw.c index 1e73719..ec44c2f 100644 --- a/draw.c +++ b/draw.c @@ -328,6 +328,13 @@ void visual_box(FILE *fc){ erase_blank_lines(MIN(y,orig_y), MAX(y, orig_y)); copy_lines_to_ring(MIN(orig_y, y), MAX(orig_y, y), NEW_STATE); + modified = 1; + goto vis_exit; + break; + case 'C':/* crop-to-region */ + copy_lines_to_ring(0, HEIGHT-1, PRV_STATE); + crop_to_rect(MIN(x, orig_x), MIN(y, orig_y), MAX(x, orig_x), MAX(y, orig_y)); + copy_lines_to_ring(0, HEIGHT-1, NEW_STATE); modified = 1; goto vis_exit; break; diff --git a/gramscii.1 b/gramscii.1 index f3ec80e..39faa09 100644 --- a/gramscii.1 +++ b/gramscii.1 @@ -384,6 +384,10 @@ subsequent yank/cut commands. Fill region. gramscii will wait for a character on input and then will fill the highlighted region with that character. .TP 5m +.BI C +Crop-to-region. Crop the chart to the content of the highlighted region. +Everything else in the screen is erased. +.TP 5m .BI v leave .B visual diff --git a/gramscii.h b/gramscii.h index 7aa9f62..9b95a4e 100644 --- a/gramscii.h +++ b/gramscii.h @@ -71,7 +71,7 @@ typedef struct{ #define progr_x(d) ((d) == DIR_L ? -1 : (d) == DIR_R ? 1 : 0) #define progr_y(d) ((d) == DIR_U ? -1 : (d) == DIR_D ? 1 : 0) -#define DEBUG 1 +/** #define DEBUG 1 **/ /** global variables **/ @@ -139,6 +139,7 @@ void erase_line(int i); void erase_screen(); void go_to(int where); void crop_to_nonblank(); +void crop_to_rect(); void erase_blank_lines(int y1, int y2); /** drawing-related functions **/ diff --git a/screen.c b/screen.c index 9a0ccb3..d0310eb 100644 --- a/screen.c +++ b/screen.c @@ -449,7 +449,7 @@ void crop_to_rect(int x1, int y1, int x2, int y2){ sprintf(screen.l[i].s, "%s", screen.l[i+y1].s + x1); screen.l[i].lst = screen.l[i+y1].lst - x1; } - while (i<=y2){ + while (i< HEIGHT){ screen.l[i].lst = -1; screen.l[i].s[0]= '\0'; i ++; -- cgit v1.2.3