From a4c6053e9df10cc4060696d6c29e84fa3105ad0e Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Fri, 19 Jul 2019 19:39:04 +0100 Subject: check if modified before exit, and save --- gramscii.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'gramscii.c') diff --git a/gramscii.c b/gramscii.c index 0d94d4a..ade73ee 100644 --- a/gramscii.c +++ b/gramscii.c @@ -145,10 +145,12 @@ char* state_str(){ void status_bar(){ + printf("\033[%d;1f\033[7m", HEIGHT+1); + printf("%100s", " "); printf("\033[%d;1f\033[7m", HEIGHT+1); 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(" [%s]", fname ); printf("\033[0m"); } @@ -302,8 +304,10 @@ void get_box(){ status_bar(); show_cursor(); } - if (c == 'b') + if (c == 'b'){ draw_box(orig_x, orig_y, FIX); + modified = 1; + } redraw(); state = MOVE; } @@ -392,8 +396,10 @@ void get_arrow(){ status_bar(); show_cursor(); } - if (c == 'a') + if (c == 'a'){ draw_arrow(orig_x, orig_y, arrow, arrow_len, FIX); + modified = 1; + } redraw(); state = MOVE; } @@ -435,7 +441,7 @@ void write_file(){ if (!fname[0] || force_new){ get_string(fname, 255); if (f=fopen(fname, "r")){ - if (!is_yes(get_key("File exists. Overwrite [y/N]?")) ){ + if (!is_yes(get_key("File exists. Overwrite [y/n]?")) ){ fclose(f); return; } @@ -450,6 +456,7 @@ void write_file(){ fprintf(f, "%s\n", screen[i]); } fclose(f); + modified = 0; get_key("File saved."); } @@ -533,6 +540,7 @@ void delete(){ check_bound(); step = 1; do_delete(orig_x, orig_y); + modified = 1; orig_x = x; orig_y = y; redraw(); @@ -542,6 +550,17 @@ void delete(){ state = MOVE; } +void check_modified(){ + + if (modified){ + if (!is_yes(get_key("Unsaved changes. Write to file [y/n]?")) ){ + return; + } + write_file(0); + } +} + + void commands(){ @@ -617,8 +636,9 @@ void commands(){ case '>': toggle_end_mark(); break; - case 'Q': case 'q': + check_modified(); + case 'Q': cleanup(0); exit(0); break; -- cgit v1.2.3