summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-07-19 15:38:14 +0100
committerKatolaZ <katolaz@freaknet.org>2019-07-19 15:38:14 +0100
commita2bf8545d73621de7cfa3a06663d1b94fdc668c4 (patch)
tree8886c1f6098bb09f5a1f7d1f42b2b13fa2c1b0a5
parent34a0ec991e4985d3ca4719ffc696f681370e14fc (diff)
fix arrow pointer -- toggle start and end markers
-rw-r--r--TODO4
-rw-r--r--gramscii.c63
2 files changed, 54 insertions, 13 deletions
diff --git a/TODO b/TODO
index e9d7819..1b6139d 100644
--- a/TODO
+++ b/TODO
@@ -1,13 +1,15 @@
+ optimize redraws (i.e., avoid to redraw if possible)
- (?) change cursor shape according to action
- save to file
-- implement arrow
+- implement auto-arrow 'A' (automatic end-char)
+- implement delete 'x' or 'd'
- manage special chars (DEL/CANC) during text insert
(also do not print unmanaged chars!)
- load from file
- insert file at position
- get screen geometry
- allow scrolling (both vertical and horizontal)
+* implement arrow
* set different line styles (done for hl, vl, corner)
* add status bar
* implement box
diff --git a/gramscii.c b/gramscii.c
index 2cc7213..1d75b34 100644
--- a/gramscii.c
+++ b/gramscii.c
@@ -23,6 +23,8 @@
#define DIR_D 0x04
#define DIR_L 0x08
+#define DIR_HOR (DIR_R | DIR_L)
+#define DIR_VER (DIR_D | DIR_U)
#define WIDTH 100
#define HEIGHT 25
@@ -54,12 +56,20 @@ char corner;
char hlines[] = {"-~=#@._ "};
char vlines[] = {"|H#@:;i "};
char corners[] = {"+'H#@.\""};
+char st_marks[] = {"+o-|<>^v"};
+char end_marks[] = {">+o-|<^v"};
+
int hlines_sz= sizeof(hlines) -1;
int vlines_sz= sizeof(vlines) -1;
int corners_sz = sizeof(corners) -1;
-int cur_hl, cur_vl, cur_corn;
+int stmarks_sz = sizeof(st_marks) - 1;
+int endmarks_sz = sizeof(st_marks) - 1;
+
+int cur_hl, cur_vl, cur_corn, cur_start, cur_end;
char line_h;
char line_v;
+char mark_st;
+char mark_end;
struct termios t1, t2;
@@ -99,8 +109,11 @@ void init_screen(){
cur_corn = 0;
corner = corners[0];
cur_hl = cur_vl = 0;
+ cur_start = cur_end = 0;
line_h = hlines[cur_hl];
line_v = vlines[cur_vl];
+ mark_st = st_marks[cur_start];
+ mark_end = end_marks[cur_end];
}
char* state_str(){
@@ -123,8 +136,8 @@ char* state_str(){
void status_bar(){
printf("\033[%d;1f\033[7m", HEIGHT+1);
- printf(" x: %3d y: %3d -- mode: %4s hl: %c vl: %c cn: %c %10s",
- x, y, state_str(), line_h, line_v, corner, "");
+ printf(" x: %3d y: %3d -- mode: %4s hl: %c vl: %c cn: %c <: %c >: %c %10s",
+ x, y, state_str(), line_h, line_v, corner, mark_st, mark_end, "");
printf("\033[0m");
}
@@ -297,12 +310,9 @@ int progr_y(int dir){
}
-/* FIXME: fix pointer position */
-/* FIXME: set initial and final markers */
-/* FIXME: draw "corner" as first char after change of dir */
void draw_arrow(int x, int y, char *a, int a_len, int fix){
- int i, j;
+ int i, j, cur_dir;
char line;
void (*f)(int, int, char);
@@ -312,20 +322,31 @@ void draw_arrow(int x, int y, char *a, int a_len, int fix){
else
f = draw_xy;
+ f(x,y,mark_st);
if (!a_len){
- f(x,y,corner);
+ show_cursor();
return;
}
- line = (a[0] & DIR_L) || (a[0] & DIR_R) ? line_h : line_v;
- f(x,y,line);
+ cur_dir=DIR_N;
for (i=0; i<a_len; i+=2){
+ if (i>0) {
+ /* If we are switching between horizontal and vertical, put a "corner" */
+ if (((cur_dir & DIR_HOR) && (a[i] & DIR_VER)) ||
+ ((cur_dir & DIR_VER) && (a[i] & DIR_HOR))){
+ f(x,y,corner);
+ show_cursor();
+ }
+ }
for(j=0; j<a[i+1]; j++){
line = (a[i] & DIR_L) || (a[i] & DIR_R) ? line_h : line_v;
x += progr_x(a[i]);
y += progr_y(a[i]);
f(x, y, line);
}
+ /* f(x,y,mark_end);*/
+ cur_dir = a[i];
}
+ f(x,y,mark_end);
show_cursor();
}
@@ -345,7 +366,7 @@ void get_arrow(){
redraw();
step = 1;
- //draw_arrow(x,y,NOFIX);
+ draw_arrow(x,y, arrow, 0, NOFIX);
while((c=getchar())!=EOF && c != 27 && c!= 'a'){
switch(c){
case 'H': step = 5;
@@ -417,6 +438,18 @@ void toggle_vline(){
}
+void toggle_st_mark(){
+
+ cur_start = (cur_start + 1 ) % stmarks_sz;
+ mark_st = st_marks[cur_start];
+}
+
+void toggle_end_mark(){
+
+ cur_end = (cur_end+ 1 ) % endmarks_sz;
+ mark_end = end_marks[cur_end];
+}
+
void commands(){
char c;
@@ -467,9 +500,15 @@ void commands(){
case '|':
toggle_vline();
break;
- case '+':
+ case '+':
toggle_corner();
break;
+ case '<':
+ toggle_st_mark();
+ break;
+ case '>':
+ toggle_end_mark();
+ break;
case 'Q':
case 'q':
cleanup(0);