From 89157d00fc4110055d5816cd1897e4def120bcaf Mon Sep 17 00:00:00 2001 From: dam Date: Tue, 7 May 2024 18:14:45 +0100 Subject: Fixed two very nasty bugs. --- modules/TUI/module.jai | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'modules') diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai index f2a3a23..612f93e 100644 --- a/modules/TUI/module.jai +++ b/modules/TUI/module.jai @@ -177,8 +177,9 @@ Style :: struct { set_style :: (style: Style) { - auto_release_temp(); - + auto_release_temp(); // TODO Does this breaks if the context.tui_buffer is a temporary buffer... and we're writting to it? + + // TODO If context.tui_buffer is temporary... this will fail.... right? builder := ifx context.tui_buffer != null then context.tui_buffer else *temp_buffer; #if COLOR_MODE_BITS == { @@ -497,10 +498,6 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { assert_is_active(); assert(count_limit >= 0, "Invalid arguments passed to read_input_line(): 'count_limit' must be greater-than or equal to 0."); - // builder := String_Builder.{ allocator = temporary_allocator }; - // builder := String_Builder.{}; - // init_string_builder(*builder, 10000); - // reset(*builder); builder := temp_buffer; str := alloc_string(count_limit); @@ -529,8 +526,7 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { for chars_count..count_limit-1 append(*builder, " "); } print_to_builder(*builder, Commands.SetCursorPosition, y, x+idx); - // write_builder(*builder); // TODO Not sure why this is not working... - write_string(builder_to_string(*builder,, allocator = temporary_allocator)); + write_builder(*builder); // Process input key. key = get_key(); @@ -560,7 +556,7 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { if idx == 0 continue; idx -= 1; delete_character(*str, idx); - + case; if is_escape_code(key) continue; @@ -571,7 +567,7 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { if buff_idx > count_limit - key_str.count then continue; // Move text to allow inserting new character. - for < count_limit..buff_idx+key_str.count { + for < count_limit-1..buff_idx + key_str.count-1 { str.data[it] = str.data[it-key_str.count]; } @@ -602,7 +598,7 @@ draw_box :: (x: int, y: int, width: int, height: int) { assert_is_active(); assert(x > 0 && y > 0 && width > 1 && height > 1, "Invalid arguments passed to draw_box(): 'x' and 'y' must be greater-than 0; 'width' and 'height' must be greater-than 1."); - auto_release_temp(); + auto_release_temp(); // TODO Does this breaks if the context.tui_buffer is a temporary buffer... and we're writting to it? builder := ifx context.tui_buffer != null then context.tui_buffer else *temp_buffer; -- cgit v1.2.3