summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-08-01 11:26:12 +0100
committerKatolaZ <katolaz@freaknet.org>2019-08-01 11:26:12 +0100
commit08485aacd8d561f2650175b7a16211262396b2ce (patch)
treedda64aa4e35020ee230d53bcf1aa0e66c8fdd1c6
parentf660595c236a21555d3558dd51afae4a67d651a3 (diff)
add undo in erase mode
-rw-r--r--TODO10
-rw-r--r--draw.c16
-rw-r--r--gramscii.125
-rw-r--r--screen.c2
4 files changed, 40 insertions, 13 deletions
diff --git a/TODO b/TODO
index ed2ceaf..ad0cba0 100644
--- a/TODO
+++ b/TODO
@@ -1,9 +1,4 @@
+ optimize redraws (redraw only the modified rectangle)
-+ undo (by storing lines changed across insert/remove operations)
- * re-organise undo-ring management
- * add undo for arrow mode
- * add undo for text mode
- - add undo for erase mode
- fix bug with 'g' commands in arrow mode
- add screen geometry option (-g 25x80?)
- read file at point
@@ -23,6 +18,11 @@
- allow scrolling (both vertical and horizontal)
- catch SIGWINCH and react appropriately (after scrolling is
enabled)
+* undo (by storing lines changed across insert/remove operations)
+ * re-organise undo-ring management
+ * add undo for arrow mode
+ * add undo for text mode
+ * add undo for erase mode
* visual selection
* crop-to-rectangle
* yank
diff --git a/draw.c b/draw.c
index bc6657d..ae90458 100644
--- a/draw.c
+++ b/draw.c
@@ -168,7 +168,6 @@ update_box:
void draw_arrow(int x, int y, char *a, int a_len, int fix){
- /* FIXME: copy affected lines to undo */
int i, j, cur_dir;
char line;
void (*f)(int, int, char);
@@ -285,13 +284,24 @@ void erase(FILE *fc){
/*FIXME: add affected lines to undo */
char c;
int orig_x = x, orig_y = y;
+ char first = 1, opened = 0;
status_bar();
show_cursor();
- invalidate_undo();
while((c=fgetc(fc))!=EOF && c!=27 && c!= 'x' && c != '\n'){
if (!move_around(c, fc)) continue;
check_bound();
+ if (first ||
+ (y != orig_y && ! opened) ||
+ (y == orig_y && x != orig_x && !opened) ){
+ copy_lines_to_ring(MIN(y, orig_y), MAX(y, orig_y), PRV_STATE);
+ first = 0;
+ opened = 1;
+ }
do_erase(orig_x, orig_y);
+ if (y != orig_y && opened){
+ copy_lines_to_ring(MIN(y, orig_y), MAX(y, orig_y), NEW_STATE);
+ opened = 0;
+ }
step = 1;
modified = 1;
orig_x = x;
@@ -300,6 +310,8 @@ void erase(FILE *fc){
status_bar();
show_cursor();
}
+ if (opened)
+ copy_lines_to_ring(y, y, NEW_STATE);
mode = MOVE;
}
diff --git a/gramscii.1 b/gramscii.1
index 036ccf5..575a2fc 100644
--- a/gramscii.1
+++ b/gramscii.1
@@ -26,6 +26,26 @@ available for further processing.
.TP
.BI -h
Print short usage unstructions and exit.
+.PP
+If one or more files are provided after the last option, gramscii will
+consider them command files and will read them one after the other
+(i.e., as if the characters in the file were typed while gramscii was
+running), before accepting commands from stdin. This allows to use
+gramscii scripts. For instance, if you start gramscii as:
+.EX
+
+ gramscii file.txt
+
+.EE
+and "file.txt" contains the lines:
+.EX
+
+ gg10lbLLJJb
+ gg10l15jbLLJJ
+
+.EE
+then gramscii will show two boxes and then will start accepting
+commands as usual.
.SH COMMANDS
gramscii is a visual modal editor. Commands are associated to
keystrokes, and keystrokes have different meaning in different modes.
@@ -537,11 +557,6 @@ would automatically save the screen into "filename".
gramscii currently manages only a fixed screen of the same size of the
screen where it starts from. This will be changed in a future release to
support scrolling and "virtual" screens of any (reasonable) size.
-.PP
-Undo commands are only available in box, visual (cut, fill), arrow, and
-text mode, and for copy/paste operations. gramscii currently does
-.B not
-support undo commands for erase mode. This will be fixed soon.
.SH AUTHORS
gramscii is written and maintained by Vincenzo "KatolaZ" Nicosia
<katolaz@freaknet.org>. You can use, copy, modify, and redistribute
diff --git a/screen.c b/screen.c
index d0310eb..e347ea3 100644
--- a/screen.c
+++ b/screen.c
@@ -445,7 +445,7 @@ void crop_to_rect(int x1, int y1, int x2, int y2){
int i;
for (i=0; i<= y2-y1; i ++){
- ensure_line_length(&(screen.l[i]), screen.l[i+y1].lst);
+ ensure_line_length(&(screen.l[i]), screen.l[i+y1].lst+1);
sprintf(screen.l[i].s, "%s", screen.l[i+y1].s + x1);
screen.l[i].lst = screen.l[i+y1].lst - x1;
}