From 1b0d0520bc12c3b6ea56417915a4c758effafbfb Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 31 Jul 2024 07:37:56 +0200 Subject: [PATCH] Append to end of console --- src/text_editor/commands.cpp | 29 +++++++++++++++-------------- src/text_editor/commands_window.cpp | 4 ++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 211df22..6f74062 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -382,35 +382,36 @@ bool GlobalCommand(Event event) { return run_window_command; } +void AppendToConsole(String16 string) { + Buffer *buffer = GetBuffer("*console*"); + ReplaceText(buffer, GetEndAsRange(*buffer), string); + ReplaceText(buffer, GetEndAsRange(*buffer), L"\n"); +} + +void AppendToConsole(String string) { + Scratch scratch; + String16 string16 = ToString16(scratch, string); + AppendToConsole(string16); +} + void ReportErrorf(const char *fmt, ...) { Scratch scratch; STRING_FORMAT(scratch, fmt, string); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", string.data, NULL); - - Buffer *buffer = GetBuffer("*console*"); - String16 string16 = ToString16(scratch, string); - ReplaceText(buffer, {}, string16); + AppendToConsole(string); } void ReportConsolef(const char *fmt, ...) { Scratch scratch; STRING_FORMAT(scratch, fmt, string); - String16 string16 = ToString16(scratch, string); - Buffer *buffer = GetBuffer("*console*"); - ReplaceText(buffer, {}, string16); - ReplaceText(buffer, Rng(string16.len), L"\n"); + AppendToConsole(string); } void ReportWarningf(const char *fmt, ...) { Scratch scratch; STRING_FORMAT(scratch, fmt, string); String16 string16 = ToString16(scratch, string); - - { - Buffer *buffer = GetBuffer("*console*"); - ReplaceText(buffer, {}, string16); - ReplaceText(buffer, Rng(string16.len), L"\n"); - } + AppendToConsole(string16); { Buffer *buffer = GetBuffer("*popup*"); diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index dc1343e..acc5ded 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -626,12 +626,12 @@ void WindowCommand(Event event, Window *window, View *view) { } } - if (Ctrl(SDLK_S) && buffer->dirty) { + if (Ctrl(SDLK_S)) { String16 string16 = GetString(*buffer); Scratch scratch; String string = ToString(scratch, string16); bool success = false; - if (!StartsWith(string, "*")) success = WriteFile(buffer->name, string); + success = WriteFile(buffer->name, string); if (success) { buffer->dirty = false;