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 --- TODO | 13 +++++- gramscii.1 | 19 +++++--- gramscii.c | 145 ++++++++++++++++++++++++++++++++++--------------------------- 3 files changed, 108 insertions(+), 69 deletions(-) diff --git a/TODO b/TODO index 0f4dc1c..eb18bd3 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,17 @@ + optimize redraws (i.e., avoid to redraw if possible) -- (?) change cursor shape according to action +- move configs in config.h +- add Makefile - auto-arrow 'A' (automatic end-char) - change screen management (i.e., use an array of lines) - read file at point +- parse control characters + - parse arrows (text-mode will allow movements as well) +- implement CTRL+G as abort (aside ESC) +- change "g" command: + - g-g (goto top-left) + - g-G (goto bottom-right) + - g-m (goto middle) + - g-[hjkl] (goto leftmost, bottom, top, rightmost) + visual selection - crop - yank/put @@ -13,6 +22,8 @@ (also do not print unmanaged chars!) - get screen geometry - allow scrolling (both vertical and horizontal) +* move style commands in a separate function + (and allow style change in all the modes...) * add "vis" (for visual) in mode strings * implement "." to reset styles to defaults. * load from file diff --git a/gramscii.1 b/gramscii.1 index 1ee0234..67a42cd 100644 --- a/gramscii.1 +++ b/gramscii.1 @@ -17,7 +17,9 @@ keystrokes, and keystrokes have different meaning in different modes. The default mode is .B move mode, which allows the user to move the cursor around the screen. -Exiting from any other mode automatically puts gramscii in +Exiting from any other mode (either via pressing +.B [ESC] +or by toggling the current mode) automatically puts gramscii in .B move mode. There are four classes of commands in gramscii, namely .B GENERAL, @@ -195,7 +197,9 @@ while in .BI erase mode, the current erase operation is aborted. Press .B x -again to make the erase permanent. +again to make the erase permanent and return to +.B move +mode. .TP 7m .BI i Enter @@ -255,8 +259,13 @@ mode. .RE .SS STYLES -The following commands can be used to customise the style of lines, -corners, and arrow start and end points: +The style of lines, corners and markers can be changed at any time while +in +.B move, +.B box, +and +.B arrow +mode. The following style commands are available: .TP 5m .B . (dot) Reset all styles to their default values. @@ -362,7 +371,7 @@ would automatically save the screen into "filename". .SH BUGS gramscii currently manages only a fixed screen of 25 rows by 100 columns. This will be changed in a future release to support scrolling -and "virtual" screen of any (reasonable) size. +and "virtual" screens of any (reasonable) size. .PP gramscii currently does .B not 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