ref: 2e556815eb1d50d2a5d22984f728f14bb7ee9f99
parent: 12dfcde0b558da5330c50bc7b617ba46cbe3f1a1
author: cancel <cancel@cancel.fm>
date: Tue Dec 11 22:18:06 EST 2018
Add message on successful save
--- a/tui_main.c
+++ b/tui_main.c
@@ -1460,10 +1460,13 @@
}
bool app_hacky_try_save(App_state* a) {
- if (!a->filename) return false;
- if (a->field.height == 0 || a->field.width == 0) return false;
+ if (!a->filename)
+ return false;
+ if (a->field.height == 0 || a->field.width == 0)
+ return false;
FILE* f = fopen(a->filename, "w");
- if (!f) return false;
+ if (!f)
+ return false;
field_fput(&a->field, f);
fclose(f);
return true;
@@ -1849,9 +1852,35 @@
app_input_character(&app_state, '.');
break;
- case KEY_F(2):
- app_hacky_try_save(&app_state);
- break;
+ case KEY_F(2): {
+ if (app_state.is_playing) {
+ app_input_cmd(&app_state, App_input_cmd_toggle_play_pause);
+ }
+ bool ok = app_hacky_try_save(&app_state);
+ werase(stdscr);
+ notimeout(stdscr, FALSE);
+ wmove(stdscr, 0, 0);
+ if (ok) {
+ wprintw(stdscr, "Saved file %s\nPress any key to continue\n",
+ app_state.filename);
+ } else {
+ wprintw(stdscr, "FAILED to save %s\nPress any key to continue\n",
+ app_state.filename);
+ }
+ bool did_resize = false;
+ for (;;) {
+ int key0 = wgetch(stdscr);
+ if (key0 == KEY_RESIZE)
+ did_resize = true;
+ if (key0 != KEY_RESIZE && key0 != ERR)
+ break;
+ }
+ werase(stdscr);
+ app_state.is_draw_dirty = true;
+ if (did_resize)
+ ungetch(KEY_RESIZE);
+ wtimeout(stdscr, cur_timeout);
+ } break;
default:
if (key >= CHAR_MIN && key <= CHAR_MAX && is_valid_glyph((Glyph)key)) {