summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-19 00:03:33 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-19 00:03:38 -0500
commit9ec5a4752523fe4aa45cc19557370ad8b180d046 (patch)
treec6f9b7f36844ef329ac40f95794a0273cb5ac177 /main.c
parentba559cc360162e02cfc79885637c9247bcecc0d8 (diff)
better errors, saving
Diffstat (limited to 'main.c')
-rw-r--r--main.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/main.c b/main.c
index 8f40828..93bac8a 100644
--- a/main.c
+++ b/main.c
@@ -68,14 +68,8 @@ int main(void) {
TextBuffer text_buffer;
buffer_create(&text_buffer, font);
- {
- FILE *fp = fopen("test.txt", "rb");
- assert(fp);
- bool success = buffer_load_file(&text_buffer, fp);
- fclose(fp);
- if (!success)
- die("Error loading file.");
- }
+ if (!buffer_load_file(&text_buffer, "test.txt"))
+ die("Error loading file: %s", buffer_geterr(&text_buffer));
Uint32 time_at_last_frame = SDL_GetTicks();
@@ -141,6 +135,13 @@ int main(void) {
else
buffer_backspace_at_cursor(&text_buffer, 1);
break;
+ case SDLK_s:
+ if (ctrl) {
+ if (!buffer_save(&text_buffer)) {
+ printf("Error saving: %s.", buffer_geterr(&text_buffer));
+ }
+ }
+ break;
}
} break;
case SDL_TEXTINPUT: {