From 4cb5948229fea24c9a2eb3413d6dbe53613bada7 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Sun, 21 Jul 2019 00:11:03 +0100 Subject: style change in box and arrow modes + fix manpage --- gramscii.c | 145 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 82 insertions(+), 63 deletions(-) (limited to 'gramscii.c') diff --git a/gramscii.c b/gramscii.c index 2913fca..1a21350 100644 --- a/gramscii.c +++ b/gramscii.c @@ -362,6 +362,33 @@ void toggle_end_mark(){ mark_end = end_marks[cur_end]; } +int change_style(char c){ + switch(c){ + case '-': + toggle_hline(); + break; + case '|': + toggle_vline(); + break; + case '+': + toggle_corner(); + break; + case '<': + toggle_st_mark(); + break; + case '>': + toggle_end_mark(); + break; + case '.': + reset_styles(); + break; + default: + return 0; + } + return c; +} + + /***** text, box, arrows *****/ @@ -430,10 +457,14 @@ void get_box(){ step = 1; draw_box(x,y,NOFIX); while((c=getchar())!=EOF && c != 27 && c!= 'b'){ - if (!move_around(c)) continue; + if (change_style(c)) + goto update_box; + if (!move_around(c)) + continue; check_bound(); redraw(); step = 1; +update_box: draw_box(orig_x, orig_y, NOFIX); status_bar(); show_cursor(); @@ -504,7 +535,10 @@ void get_arrow(){ step = 1; draw_arrow(x,y, arrow, 0, NOFIX); while((c=getchar())!=EOF && c != 27 && c!= 'a'){ - if (!move_around(c)) continue; + if (change_style(c)) + goto update_arrow; + if (!move_around(c)) + continue; check_bound(); /* FIXME: if we are out of bound, do nothing? */ if (arrow_len == arrow_sz){ @@ -515,6 +549,7 @@ void get_arrow(){ arrow[arrow_len++] = step; redraw(); step = 1; +update_arrow: draw_arrow(orig_x, orig_y, arrow, arrow_len, NOFIX); status_bar(); show_cursor(); @@ -701,67 +736,51 @@ void commands(){ char c; while((c=getchar())!=EOF){ - if (!move_around(c)) switch(c){ - case 'i': - state = TEXT; - get_text(); - break; - case 'R': - redraw(); - break; - case 'b': - state = BOX; - get_box(); - break; - case 'a': - state = ARROW; - get_arrow(); - break; - case 'W': - force_new = 1;/** FALLTHROUGH **/ - case 'w': - write_file(); - break; - case 'e': - check_modified();/** FALLTHROUGH **/ - case 'E': - load_file(); - break; - case 'N': - new_file(); - break; - case 'x': - state = DEL; - delete(); - break; - case 'v': - state = VIS; - visual_box(); - break; - case '-': - toggle_hline(); - break; - case '|': - toggle_vline(); - break; - case '+': - toggle_corner(); - break; - case '<': - toggle_st_mark(); - break; - case '>': - toggle_end_mark(); - break; - case '.': - reset_styles(); - break; - case 'q': - check_modified();/** FALLTHROUGH **/ - case 'Q': - cleanup(0); - exit(0); - break; + if (!change_style(c) && !move_around(c)){ + switch(c){ + case 'i': + state = TEXT; + get_text(); + break; + case 'R': + redraw(); + break; + case 'b': + state = BOX; + get_box(); + break; + case 'a': + state = ARROW; + get_arrow(); + break; + case 'W': + force_new = 1;/** FALLTHROUGH **/ + case 'w': + write_file(); + break; + case 'e': + check_modified();/** FALLTHROUGH **/ + case 'E': + load_file(); + break; + case 'N': + new_file(); + break; + case 'x': + state = DEL; + delete(); + break; + case 'v': + state = VIS; + visual_box(); + break; + case 'q': + check_modified();/** FALLTHROUGH **/ + case 'Q': + cleanup(0); + exit(0); + break; + } } check_bound(); status_bar(); -- cgit v1.2.3