Introduction
Introduction Statistics Contact Development Disclaimer Help
visual mode (erase and fill) - gramscii - A simple editor for ASCII box-and-arr…
Log
Files
Refs
Tags
README
LICENSE
---
commit d87cf8ea7ec68de924179eb1dbaa13f4b52bd1aa
parent c8512825e3baf1525af7117affa13d00ac6b0d1d
Author: KatolaZ <[email protected]>
Date: Sat, 20 Jul 2019 14:47:12 +0100
visual mode (erase and fill)
Diffstat:
M TODO | 7 ++++---
M gramscii.c | 66 +++++++++++++++++++++++++++++…
2 files changed, 70 insertions(+), 3 deletions(-)
---
diff --git a/TODO b/TODO
@@ -2,11 +2,12 @@
- (?) change cursor shape according to action
- auto-arrow 'A' (automatic end-char)
- read file at point
-- visual selection
++ visual selection
- crop
- - fill
- - delete
- yank/put
+ * fill
+ * delete
+- change screen management (i.e., use an array of lines)
- undo (by storing lines changed across insert/remove operations)
- manage special chars (DEL/CANC) during text insert
(also do not print unmanaged chars!)
diff --git a/gramscii.c b/gramscii.c
@@ -16,6 +16,7 @@
#define ARROW 0x02
#define TEXT 0x04
#define DEL 0x08
+#define VIS 0x10
#define DIR_N 0x00
#define DIR_R 0x01
@@ -45,6 +46,9 @@
#define END 0x02
#define MIDDLE 0x04
+#define VIDEO_NRM 0
+#define VIDEO_REV 7
+
#define MIN(x,y) (x) < (y) ? (x) : (y)
#define MAX(x,y) (x) > (y) ? (x) : (y)
@@ -188,6 +192,21 @@ void erase_line(char *s){
}
}
+void erase_box(int x1, int y1, char c){
+
+ int x_incr, y_incr, i;
+
+ x_incr = x1 < x? +1: -1;
+ y_incr = y1 < y? +1: -1;
+ do{
+ i = y1;
+ do{
+ set_xy(x1, i, c);
+ } while(i != y && (1 | (i += y_incr)));
+ } while(x1 != x && (1 | (x1 += x_incr)));
+
+}
+
void erase_screen(){
int i;
for(i=0;i<HEIGHT; i++)
@@ -297,6 +316,10 @@ int progr_y(int dir){
return dir == DIR_U ? -1 : dir == DIR_D ? 1: 0;
}
+void set_video(int v){
+ printf("\033[%dm", v);
+}
+
/*** Lines and markers ***/
void toggle_hline(){
@@ -626,6 +649,45 @@ void new_file(){
modified=0;
}
+/*** Visual ***/
+
+
+void visual_box(){
+ int orig_x =x, orig_y = y;
+ char c, f = BG;
+
+ redraw();
+ step = 1;
+ set_video(VIDEO_REV);
+ draw_box(x,y,NOFIX);
+ while((c=getchar())!=EOF && c != 27 && c!= 'v'){
+ if (!move_around(c)) switch(c){
+ case 'f':/* fill */
+ f = get_key("fill char: ");
+ case 'x':/* erase */
+ erase_box(orig_x, orig_y, f);
+ modified = 1;
+ goto vis_exit;
+ break;
+ }
+ check_bound();
+ set_video(VIDEO_NRM);
+ redraw();
+ step = 1;
+ f = BG;
+ set_video(VIDEO_REV);
+ draw_box(orig_x, orig_y, NOFIX);
+ status_bar();
+ show_cursor();
+ }
+vis_exit:
+ set_video(VIDEO_NRM);
+ redraw();
+ state = MOVE;
+}
+
+
+
/*** Commands ***/
void commands(){
@@ -665,6 +727,10 @@ void commands(){
state = DEL;
delete();
break;
+ case 'v':
+ state = VIS;
+ visual_box();
+ break;
case '-':
toggle_hline();
break;
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.