From 72791d9c35be82043a2f272a8cdeb11bd676a313 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 20:37:40 -0700 Subject: some debug prints I'm starting to edit the sources from within the app in ernest. First question: why does the file navigation menu skip some files? These prints answer the question. --- commands.lua | 4 ++++ main.lua | 1 + run.lua | 1 + source.lua | 2 ++ 4 files changed, 8 insertions(+) diff --git a/commands.lua b/commands.lua index be9c9bf..29e4a3e 100644 --- a/commands.lua +++ b/commands.lua @@ -55,13 +55,16 @@ function add_hotkey_to_menu(s) end function source.draw_file_navigator() + log_start('render file navigator') for i,file in ipairs(File_navigation.candidates) do if file == 'source' then App.color(Menu_border_color) love.graphics.line(Menu_cursor-10,2, Menu_cursor-10,Menu_status_bar_height-2) end + log(2, file) add_file_to_menu(file, i == File_navigation.index) end + log_end('render file navigator') end function add_file_to_menu(s, cursor_highlight) @@ -70,6 +73,7 @@ function add_file_to_menu(s, cursor_highlight) end local width = App.width(Text_cache[s]) if Menu_cursor + width > App.screen.width - 5 then + log(2, 'skipped') return end if cursor_highlight then diff --git a/main.lua b/main.lua index fd0fe45..570a7a1 100644 --- a/main.lua +++ b/main.lua @@ -33,6 +33,7 @@ load_file_from_source_or_save_directory('drawing_tests.lua') -- but some files we want to only load sometimes function App.load() + log_new('session') if love.filesystem.getInfo('config') then Settings = json.decode(love.filesystem.read('config')) Current_app = Settings.current_app diff --git a/run.lua b/run.lua index 2dd159e..3a17225 100644 --- a/run.lua +++ b/run.lua @@ -15,6 +15,7 @@ end -- called only for real run function run.initialize(arg) + log_new('run') love.keyboard.setTextInput(true) -- bring up keyboard on touch screen love.keyboard.setKeyRepeat(true) diff --git a/source.lua b/source.lua index c752604..70b0814 100644 --- a/source.lua +++ b/source.lua @@ -11,6 +11,7 @@ function source.initialize_globals() Show_file_navigator = false File_navigation = { candidates = { + 'main', 'run', 'run_tests', 'log', @@ -56,6 +57,7 @@ end -- called only for real run function source.initialize() + log_new('source') love.keyboard.setTextInput(true) -- bring up keyboard on touch screen love.keyboard.setKeyRepeat(true) -- cgit 1.4.1-2-gfad0 From 620176263a2a2a6f2dac2940a50392e7c8bc71d1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 22:56:11 -0700 Subject: bugfix: log filenames can have 2 formats --- log_browser.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/log_browser.lua b/log_browser.lua index f65117f..5438584 100644 --- a/log_browser.lua +++ b/log_browser.lua @@ -27,7 +27,10 @@ log_browser = {} function log_browser.parse(State) for _,line in ipairs(State.lines) do if line.data ~= '' then - line.filename, line.line_number, line.data = line.data:match('%[string "([^:]*)"%]:([^:]*):%s*(.*)') + line.filename, line.line_number, line.data = line.data:match('([^:]*):([^:]*):%s*(.*)') + if line.filename == nil then + line.filename, line.line_number, line.data = line.data:match('%[string "([^:]*)"%]:([^:]*):%s*(.*)') + end line.filename = guess_source(line.filename) line.line_number = tonumber(line.line_number) if line.data:sub(1,1) == '{' then -- cgit 1.4.1-2-gfad0 From cea2730080b80e1c8d3c4ad1196429ff282b7c1c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:01:40 -0700 Subject: use a helper --- commands.lua | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/commands.lua b/commands.lua index 29e4a3e..b30013c 100644 --- a/commands.lua +++ b/commands.lua @@ -42,15 +42,13 @@ function source.draw_menu_bar() end function add_hotkey_to_menu(s) - if Text_cache[s] == nil then - Text_cache[s] = App.newText(love.graphics.getFont(), s) - end - local width = App.width(Text_cache[s]) + local s_text = to_text(s) + local width = App.width(s_text) if Menu_cursor + width > App.screen.width - 5 then return end App.color(Menu_command_color) - App.screen.draw(Text_cache[s], Menu_cursor,5) + App.screen.draw(s_text, Menu_cursor,5) Menu_cursor = Menu_cursor + width + 30 end @@ -68,20 +66,18 @@ function source.draw_file_navigator() end function add_file_to_menu(s, cursor_highlight) - if Text_cache[s] == nil then - Text_cache[s] = App.newText(love.graphics.getFont(), s) - end - local width = App.width(Text_cache[s]) + local s_text = to_text(s) + local width = App.width(s_text) if Menu_cursor + width > App.screen.width - 5 then log(2, 'skipped') return end if cursor_highlight then App.color(Menu_highlight_color) - love.graphics.rectangle('fill', Menu_cursor-5,5-2, App.width(Text_cache[s])+5*2,Editor_state.line_height+2*2) + love.graphics.rectangle('fill', Menu_cursor-5,5-2, App.width(s_text)+5*2,Editor_state.line_height+2*2) end App.color(Menu_command_color) - App.screen.draw(Text_cache[s], Menu_cursor,5) + App.screen.draw(s_text, Menu_cursor,5) Menu_cursor = Menu_cursor + width + 30 end -- cgit 1.4.1-2-gfad0 From b5ff0a4764d593baf2e729f1c1cf0a3766b710c1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:03:43 -0700 Subject: use existing local --- commands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.lua b/commands.lua index b30013c..fa45b31 100644 --- a/commands.lua +++ b/commands.lua @@ -74,7 +74,7 @@ function add_file_to_menu(s, cursor_highlight) end if cursor_highlight then App.color(Menu_highlight_color) - love.graphics.rectangle('fill', Menu_cursor-5,5-2, App.width(s_text)+5*2,Editor_state.line_height+2*2) + love.graphics.rectangle('fill', Menu_cursor-5,5-2, width+5*2,Editor_state.line_height+2*2) end App.color(Menu_command_color) App.screen.draw(s_text, Menu_cursor,5) -- cgit 1.4.1-2-gfad0 From b00232e01adfbb27f8ce7642dae726e167cd90d1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:05:08 -0700 Subject: bugfix: never skip files in file navigator --- commands.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/commands.lua b/commands.lua index fa45b31..12189ba 100644 --- a/commands.lua +++ b/commands.lua @@ -61,6 +61,9 @@ function source.draw_file_navigator() end log(2, file) add_file_to_menu(file, i == File_navigation.index) + if Menu_cursor >= App.screen.width - 5 then + break + end end log_end('render file navigator') end @@ -68,10 +71,6 @@ end function add_file_to_menu(s, cursor_highlight) local s_text = to_text(s) local width = App.width(s_text) - if Menu_cursor + width > App.screen.width - 5 then - log(2, 'skipped') - return - end if cursor_highlight then App.color(Menu_highlight_color) love.graphics.rectangle('fill', Menu_cursor-5,5-2, width+5*2,Editor_state.line_height+2*2) -- cgit 1.4.1-2-gfad0 From 56cdf607edb25230d48b4c7899e95f385ffeacc5 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:11:23 -0700 Subject: easy way to make file switching more convenient In the fullness of time, I'll want to remember previous file, type to filter, etc. But for now just don't forget where you were. This is helpful because I'm often working on either the run side or the source side, and just starting out on the right side shaves off a lot of keypresses. --- source.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/source.lua b/source.lua index 70b0814..5b92d1e 100644 --- a/source.lua +++ b/source.lua @@ -343,7 +343,6 @@ function source.keychord_pressed(chord, key) end if chord == 'C-g' then Show_file_navigator = true - File_navigation.index = 1 return end if Focus == 'edit' then -- cgit 1.4.1-2-gfad0 From 593418972c51905e3ead63d7a65c1bdd8959fd0c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:19:36 -0700 Subject: bugfix: perform matches in the right order --- log_browser.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/log_browser.lua b/log_browser.lua index 5438584..5516da9 100644 --- a/log_browser.lua +++ b/log_browser.lua @@ -27,9 +27,9 @@ log_browser = {} function log_browser.parse(State) for _,line in ipairs(State.lines) do if line.data ~= '' then - line.filename, line.line_number, line.data = line.data:match('([^:]*):([^:]*):%s*(.*)') + line.filename, line.line_number, line.data = line.data:match('%[string "([^:]*)"%]:([^:]*):%s*(.*)') if line.filename == nil then - line.filename, line.line_number, line.data = line.data:match('%[string "([^:]*)"%]:([^:]*):%s*(.*)') + line.filename, line.line_number, line.data = line.data:match('([^:]*):([^:]*):%s*(.*)') end line.filename = guess_source(line.filename) line.line_number = tonumber(line.line_number) -- cgit 1.4.1-2-gfad0 From e3f9908d136e752c183d745fad0d11d3769aecd8 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:27:02 -0700 Subject: yet another bugfix in log parsing --- log_browser.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/log_browser.lua b/log_browser.lua index 5516da9..91f02eb 100644 --- a/log_browser.lua +++ b/log_browser.lua @@ -27,9 +27,13 @@ log_browser = {} function log_browser.parse(State) for _,line in ipairs(State.lines) do if line.data ~= '' then - line.filename, line.line_number, line.data = line.data:match('%[string "([^:]*)"%]:([^:]*):%s*(.*)') + local rest + line.filename, line.line_number, rest = line.data:match('%[string "([^:]*)"%]:([^:]*):%s*(.*)') if line.filename == nil then - line.filename, line.line_number, line.data = line.data:match('([^:]*):([^:]*):%s*(.*)') + line.filename, line.line_number, rest = line.data:match('([^:]*):([^:]*):%s*(.*)') + end + if rest then + line.data = rest end line.filename = guess_source(line.filename) line.line_number = tonumber(line.line_number) -- cgit 1.4.1-2-gfad0 From c02a5ee1ff75eb80a828bcac5f73d131994dce0a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:21:02 -0700 Subject: delete some logs One open question is how to manage logs while drawing, since they can be extremely verbose. Neither tags nor depths seem like the right metaphor here, and that gives me pause that I perhaps don't see the full space of needs yet. --- commands.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/commands.lua b/commands.lua index 12189ba..ab8184f 100644 --- a/commands.lua +++ b/commands.lua @@ -53,19 +53,16 @@ function add_hotkey_to_menu(s) end function source.draw_file_navigator() - log_start('render file navigator') for i,file in ipairs(File_navigation.candidates) do if file == 'source' then App.color(Menu_border_color) love.graphics.line(Menu_cursor-10,2, Menu_cursor-10,Menu_status_bar_height-2) end - log(2, file) add_file_to_menu(file, i == File_navigation.index) if Menu_cursor >= App.screen.width - 5 then break end end - log_end('render file navigator') end function add_file_to_menu(s, cursor_highlight) -- cgit 1.4.1-2-gfad0 From 36bde53d410012c07c2e9fc543ee49c06443b4d7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:43:14 -0700 Subject: rename --- commands.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands.lua b/commands.lua index ab8184f..870743b 100644 --- a/commands.lua +++ b/commands.lua @@ -53,12 +53,12 @@ function add_hotkey_to_menu(s) end function source.draw_file_navigator() - for i,file in ipairs(File_navigation.candidates) do - if file == 'source' then + for i,filename in ipairs(File_navigation.candidates) do + if filename == 'source' then App.color(Menu_border_color) love.graphics.line(Menu_cursor-10,2, Menu_cursor-10,Menu_status_bar_height-2) end - add_file_to_menu(file, i == File_navigation.index) + add_file_to_menu(filename, i == File_navigation.index) if Menu_cursor >= App.screen.width - 5 then break end -- cgit 1.4.1-2-gfad0 From d1db41b7b814f05c3c5621fb66732cbbd741b60f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:53:05 -0700 Subject: bugfix: draw menu after everything else This is stupid; I did it right in pensieve.love to begin with. --- source.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source.lua b/source.lua index 5b92d1e..3b16b9d 100644 --- a/source.lua +++ b/source.lua @@ -221,7 +221,6 @@ function source.switch_to_file(filename) end function source.draw() - source.draw_menu_bar() edit.draw(Editor_state) if Show_log_browser_side then -- divider @@ -230,6 +229,7 @@ function source.draw() -- log_browser.draw(Log_browser_state) end + source.draw_menu_bar() end function source.update(dt) -- cgit 1.4.1-2-gfad0 From 9013eaa637bebe13742f75cf37b377b763be20e1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2022 23:53:57 -0700 Subject: source: show all files in navigator We still don't have up/down arrow keys. And we still don't have the ability to filter filenames by typing. --- commands.lua | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/commands.lua b/commands.lua index 870743b..ee5a5fa 100644 --- a/commands.lua +++ b/commands.lua @@ -53,28 +53,54 @@ function add_hotkey_to_menu(s) end function source.draw_file_navigator() + if File_navigation.num_lines == nil then + File_navigation.num_lines = source.num_lines_for_file_navigator() + end + App.color(Menu_background_color) + love.graphics.rectangle('fill', 0,Menu_status_bar_height, App.screen.width, File_navigation.num_lines * Editor_state.line_height) + local x,y = 5, Menu_status_bar_height for i,filename in ipairs(File_navigation.candidates) do if filename == 'source' then App.color(Menu_border_color) love.graphics.line(Menu_cursor-10,2, Menu_cursor-10,Menu_status_bar_height-2) end - add_file_to_menu(filename, i == File_navigation.index) + x,y = add_file_to_menu(x,y, filename, i == File_navigation.index) if Menu_cursor >= App.screen.width - 5 then break end end end -function add_file_to_menu(s, cursor_highlight) +function source.num_lines_for_file_navigator() + local result = 1 + local x = 5 + for i,filename in ipairs(File_navigation.candidates) do + local width = App.width(to_text(filename)) + if x + width > App.screen.width - 5 then + result = result+1 + x = 5 + width + else + x = x + width + 30 + end + end + return result +end + +function add_file_to_menu(x,y, s, cursor_highlight) local s_text = to_text(s) local width = App.width(s_text) + if x + width > App.screen.width - 5 then + y = y + Editor_state.line_height + x = 5 + end if cursor_highlight then App.color(Menu_highlight_color) - love.graphics.rectangle('fill', Menu_cursor-5,5-2, width+5*2,Editor_state.line_height+2*2) + love.graphics.rectangle('fill', x-5,y-2, width+5*2,Editor_state.line_height+2*2) end App.color(Menu_command_color) - App.screen.draw(s_text, Menu_cursor,5) - Menu_cursor = Menu_cursor + width + 30 + App.screen.draw(s_text, x,y) + x = x + width + 30 + return x,y end function keychord_pressed_on_file_navigator(chord, key) -- cgit 1.4.1-2-gfad0 From 5c0ce8ee36a963041f44861c8221110ff2d69647 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Sep 2022 00:01:14 -0700 Subject: indent --- commands.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/commands.lua b/commands.lua index ee5a5fa..1bc2b0d 100644 --- a/commands.lua +++ b/commands.lua @@ -75,13 +75,13 @@ function source.num_lines_for_file_navigator() local result = 1 local x = 5 for i,filename in ipairs(File_navigation.candidates) do - local width = App.width(to_text(filename)) - if x + width > App.screen.width - 5 then - result = result+1 - x = 5 + width - else - x = x + width + 30 - end + local width = App.width(to_text(filename)) + if x + width > App.screen.width - 5 then + result = result+1 + x = 5 + width + else + x = x + width + 30 + end end return result end -- cgit 1.4.1-2-gfad0 From 21b158398b6833e273852e9a7b657ca260054471 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Sep 2022 00:37:20 -0700 Subject: source: up/down in file navigator I'm starting to use logging, but it's still easier to print textual logs. --- commands.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/commands.lua b/commands.lua index 1bc2b0d..0913733 100644 --- a/commands.lua +++ b/commands.lua @@ -104,6 +104,8 @@ function add_file_to_menu(x,y, s, cursor_highlight) end function keychord_pressed_on_file_navigator(chord, key) + log(2, 'file navigator: '..chord) + log(2, ('cursor initially at %d %s'):format(File_navigation.index, File_navigation.candidates[File_navigation.index])) if chord == 'escape' then Show_file_navigator = false elseif chord == 'return' then @@ -118,5 +120,71 @@ function keychord_pressed_on_file_navigator(chord, key) if File_navigation.index < #File_navigation.candidates then File_navigation.index = File_navigation.index+1 end + elseif chord == 'down' then + file_navigator_down() + elseif chord == 'up' then + file_navigator_up() end end + +function file_navigator_up() + local y, x, width = file_coord(File_navigation.index) + local index = file_index(y-Editor_state.line_height, x, width) + if index then + File_navigation.index = index + end +end + +function file_navigator_down() + local y, x, width = file_coord(File_navigation.index) + local index = file_index(y+Editor_state.line_height, x, width) + if index then + File_navigation.index = index + end +end + +function file_coord(index) + local y,x = Menu_status_bar_height, 5 + for i,filename in ipairs(File_navigation.candidates) do + local width = App.width(to_text(filename)) + if x + width > App.screen.width - 5 then + y = y + Editor_state.line_height + x = 5 + end + if i == index then + return y, x, width + end + x = x + width + 30 + end +end + +function file_index(fy, fx, fwidth) + log_start('file index') + log(2, ('for %d %d %d'):format(fy, fx, fwidth)) + local y,x = Menu_status_bar_height, 5 + local best_guess, best_guess_x, best_guess_width + for i,filename in ipairs(File_navigation.candidates) do + local width = App.width(to_text(filename)) + if x + width > App.screen.width - 5 then + y = y + Editor_state.line_height + x = 5 + end + if y == fy then + log(2, ('%d: correct row; considering %d %s %d %d'):format(y, i, filename, x, width)) + if best_guess == nil then + log(2, 'nil') + best_guess = i + best_guess_x = x + best_guess_width = width + elseif math.abs(fx + fwidth/2 - x - width/2) < math.abs(fx + fwidth/2 - best_guess_x - best_guess_width/2) then + best_guess = i + best_guess_x = x + best_guess_width = width + end + log(2, ('best guess now %d %s %d %d'):format(best_guess, File_navigation.candidates[best_guess], best_guess_x, best_guess_width)) + end + x = x + width + 30 + end + log_end('file index') + return best_guess +end -- cgit 1.4.1-2-gfad0 From bc464fe6f1fc99af269c20e87e7be38ec26de2b3 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Sep 2022 01:11:23 -0700 Subject: start showing source menu file navigation state graphically I'm a bit leery of going down this road: - If there's a bug in how I render logs graphically that could be extremely misleading. Perhaps this suggests that the code to log things should be significantly simpler than the code that might be debugged. If writing the debug helper requires all my smarts I'm not smart enough to debug using the helper, etc. Given this idea, the fact that I'm copying production code into the logging helper is concerning. - There's a question of what code it's ok for logging helpers to depend on. This is an issue shared with tests. I often implicitly (and without meaning to) assume the presence of some well-tested helpers when writing tests. If those helpers ever break I can get into a rabbit hole of debugging. This problem might be even more insidious with logging helpers that will give me no indication when they break. Still and all, it's cool to see menus in my logs. Let's see if it's useful. --- commands.lua | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- source.lua | 1 + 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/commands.lua b/commands.lua index 0913733..bf662ec 100644 --- a/commands.lua +++ b/commands.lua @@ -54,10 +54,10 @@ end function source.draw_file_navigator() if File_navigation.num_lines == nil then - File_navigation.num_lines = source.num_lines_for_file_navigator() + File_navigation.num_lines = source.num_lines_for_file_navigator(File_navigation.candidates) end App.color(Menu_background_color) - love.graphics.rectangle('fill', 0,Menu_status_bar_height, App.screen.width, File_navigation.num_lines * Editor_state.line_height) + love.graphics.rectangle('fill', 0,Menu_status_bar_height, App.screen.width, File_navigation.num_lines * Editor_state.line_height + --[[highlight padding]] 2) local x,y = 5, Menu_status_bar_height for i,filename in ipairs(File_navigation.candidates) do if filename == 'source' then @@ -71,10 +71,10 @@ function source.draw_file_navigator() end end -function source.num_lines_for_file_navigator() +function source.num_lines_for_file_navigator(candidates) local result = 1 local x = 5 - for i,filename in ipairs(File_navigation.candidates) do + for i,filename in ipairs(candidates) do local width = App.width(to_text(filename)) if x + width > App.screen.width - 5 then result = result+1 @@ -105,7 +105,7 @@ end function keychord_pressed_on_file_navigator(chord, key) log(2, 'file navigator: '..chord) - log(2, ('cursor initially at %d %s'):format(File_navigation.index, File_navigation.candidates[File_navigation.index])) + log(2, {name='file_navigator_state', files=File_navigation.candidates, index=File_navigation.index}) if chord == 'escape' then Show_file_navigator = false elseif chord == 'return' then @@ -127,6 +127,54 @@ function keychord_pressed_on_file_navigator(chord, key) end end +function log_render.file_navigator_state(o, x,y, w) + -- duplicate structure of source.draw_file_navigator + local num_lines = source.num_lines_for_file_navigator(o.files) + local h = num_lines * Editor_state.line_height + App.color(Menu_background_color) + love.graphics.rectangle('fill', x,y, w,h) + -- compute the x,y,width of the current index (in offsets from top left) + local x2,y2 = 0,0 + local width = 0 + for i,filename in ipairs(o.files) do + local filename_text = to_text(filename) + width = App.width(filename_text) + if x2 + width > App.screen.width - 5 then + y2 = y2 + Editor_state.line_height + x2 = 0 + end + if i == o.index then + break + end + x2 = x2 + width + 30 + end + -- figure out how much of the menu to display + local menu_xmin = math.max(0, x2-w/2) + local menu_xmax = math.min(App.screen.width, x2+w/2) + -- now selectively print out entries + local x3,y3 = 0,y -- x3 is relative, y3 is absolute + local width = 0 + for i,filename in ipairs(o.files) do + local filename_text = to_text(filename) + width = App.width(filename_text) + if x3 + width > App.screen.width - 5 then + y3 = y3 + Editor_state.line_height + x3 = 0 + end + if i == o.index then + App.color(Menu_highlight_color) + love.graphics.rectangle('fill', x + x3-menu_xmin - 5, y3-2, width+5*2, Editor_state.line_height+2*2) + end + if x3 >= menu_xmin and x3 + width < menu_xmax then + App.color(Menu_command_color) + App.screen.draw(filename_text, x + x3-menu_xmin, y3) + end + x3 = x3 + width + 30 + end + -- + return h+20 +end + function file_navigator_up() local y, x, width = file_coord(File_navigation.index) local index = file_index(y-Editor_state.line_height, x, width) diff --git a/source.lua b/source.lua index 3b16b9d..13a66cd 100644 --- a/source.lua +++ b/source.lua @@ -1,4 +1,5 @@ source = {} +log_render = {} Editor_state = {} -- cgit 1.4.1-2-gfad0 From 89b30a62efda3aa662826801e3e8d70779996569 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Sep 2022 01:26:20 -0700 Subject: support mouse clicks in file navigator --- app.lua | 4 ++++ commands.lua | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app.lua b/app.lua index 994f0c7..62ecd38 100644 --- a/app.lua +++ b/app.lua @@ -194,6 +194,10 @@ function App.color(color) love.graphics.setColor(color.r, color.g, color.b, color.a) end +function colortable(app_color) + return {app_color.r, app_color.g, app_color.b, app_color.a} +end + App.time = 1 function App.getTime() return App.time diff --git a/commands.lua b/commands.lua index bf662ec..71d74f0 100644 --- a/commands.lua +++ b/commands.lua @@ -93,10 +93,17 @@ function add_file_to_menu(x,y, s, cursor_highlight) y = y + Editor_state.line_height x = 5 end + local color = Menu_background_color if cursor_highlight then - App.color(Menu_highlight_color) - love.graphics.rectangle('fill', x-5,y-2, width+5*2,Editor_state.line_height+2*2) + color = Menu_highlight_color end + button(Editor_state, 'menu', {x=x-5, y=y-2, w=width+5*2, h=Editor_state.line_height+2*2, color=colortable(color), + onpress1 = function() + local candidate = guess_source(s..'.lua') + source.switch_to_file(candidate) + Show_file_navigator = false + end + }) App.color(Menu_command_color) App.screen.draw(s_text, x,y) x = x + width + 30 -- cgit 1.4.1-2-gfad0 From 936d3b4616007916c21fba86fec7a67b9ae72ea2 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Sep 2022 01:28:05 -0700 Subject: bugfix: disable typing while file navigator is open --- source.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source.lua b/source.lua index 13a66cd..c8c83a4 100644 --- a/source.lua +++ b/source.lua @@ -307,6 +307,9 @@ end function source.textinput(t) Cursor_time = 0 -- ensure cursor is visible immediately after it moves + if Show_file_navigator then + return + end if Focus == 'edit' then return edit.textinput(Editor_state, t) else -- cgit 1.4.1-2-gfad0 From 141d41aec536a960096e777cb9f6ceef08f121a1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Sep 2022 01:32:23 -0700 Subject: hide editor cursor while in file navigator --- source.lua | 2 +- source_edit.lua | 4 ++-- source_text.lua | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source.lua b/source.lua index c8c83a4..69b2d4f 100644 --- a/source.lua +++ b/source.lua @@ -222,7 +222,7 @@ function source.switch_to_file(filename) end function source.draw() - edit.draw(Editor_state) + edit.draw(Editor_state, --[[hide cursor?]] Show_file_navigator) if Show_log_browser_side then -- divider App.color(Divider_color) diff --git a/source_edit.lua b/source_edit.lua index c17ce26..4f55083 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -124,7 +124,7 @@ function edit.fixup_cursor(State) end end -function edit.draw(State) +function edit.draw(State, hide_cursor) State.button_handlers = {} App.color(Text_color) if #State.lines ~= #State.line_cache then @@ -170,7 +170,7 @@ function edit.draw(State) end, }) end - y, State.screen_bottom1.pos, State.screen_bottom1.posB = Text.draw(State, line_index, y, startpos, startposB) + y, State.screen_bottom1.pos, State.screen_bottom1.posB = Text.draw(State, line_index, y, startpos, startposB, hide_cursor) y = y + State.line_height --? print('=> y', y) elseif line.mode == 'drawing' then diff --git a/source_text.lua b/source_text.lua index 5959fd5..3e70343 100644 --- a/source_text.lua +++ b/source_text.lua @@ -4,7 +4,7 @@ AB_padding = 20 -- space in pixels between A side and B side -- draw a line starting from startpos to screen at y between State.left and State.right -- return the final y, and pos,posB of start of final screen line drawn -function Text.draw(State, line_index, y, startpos, startposB) +function Text.draw(State, line_index, y, startpos, startposB, hide_cursor) local line = State.lines[line_index] local line_cache = State.line_cache[line_index] line_cache.starty = y @@ -18,7 +18,7 @@ function Text.draw(State, line_index, y, startpos, startposB) return y, screen_line_starting_pos end if Focus == 'edit' and State.cursor1.pos then - if State.search_term == nil then + if not hide_cursor and not State.search_term then if line_index == State.cursor1.line and State.cursor1.pos == pos then Text.draw_cursor(State, x, y) end @@ -64,7 +64,7 @@ function Text.draw(State, line_index, y, startpos, startposB) --? if line_index == 8 then print('a') end if Focus == 'edit' and State.cursor1.posB then --? if line_index == 8 then print('b') end - if State.search_term == nil then + if not hide_cursor and not State.search_term then --? if line_index == 8 then print('c', State.cursor1.line, State.cursor1.posB, line_index, pos) end if line_index == State.cursor1.line and State.cursor1.posB == pos then Text.draw_cursor(State, x, y) -- cgit 1.4.1-2-gfad0 From d141822e6cf2516d60fe168dd4f620389f0ab5da Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Sep 2022 01:53:36 -0700 Subject: filter candidates in file navigator --- commands.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ source.lua | 5 ++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/commands.lua b/commands.lua index 71d74f0..583d1ef 100644 --- a/commands.lua +++ b/commands.lua @@ -53,6 +53,10 @@ function add_hotkey_to_menu(s) end function source.draw_file_navigator() + App.color(Menu_command_color) + local filter_text = to_text(File_navigation.filter) + App.screen.draw(filter_text, 5, 5) + draw_cursor(5 + App.width(filter_text), 5) if File_navigation.num_lines == nil then File_navigation.num_lines = source.num_lines_for_file_navigator(File_navigation.candidates) end @@ -71,6 +75,27 @@ function source.draw_file_navigator() end end +function draw_cursor(x, y) + -- blink every 0.5s + if math.floor(Cursor_time*2)%2 == 0 then + App.color(Cursor_color) + love.graphics.rectangle('fill', x,y, 3,Editor_state.line_height) + end +end + +function source.file_navigator_candidates() + if File_navigation.filter == '' then + return File_navigation.all_candidates + end + local result = {} + for _,filename in ipairs(File_navigation.all_candidates) do + if starts_with(filename, File_navigation.filter) then + table.insert(result, filename) + end + end + return result +end + function source.num_lines_for_file_navigator(candidates) local result = 1 local x = 5 @@ -115,10 +140,22 @@ function keychord_pressed_on_file_navigator(chord, key) log(2, {name='file_navigator_state', files=File_navigation.candidates, index=File_navigation.index}) if chord == 'escape' then Show_file_navigator = false + File_navigation.index = 1 + File_navigation.filter = '' + File_navigation.candidates = File_navigation.all_candidates elseif chord == 'return' then local candidate = guess_source(File_navigation.candidates[File_navigation.index]..'.lua') source.switch_to_file(candidate) Show_file_navigator = false + File_navigation.index = 1 + File_navigation.filter = '' + File_navigation.candidates = File_navigation.all_candidates + elseif chord == 'backspace' then + local len = utf8.len(File_navigation.filter) + local byte_offset = Text.offset(File_navigation.filter, len) + File_navigation.filter = string.sub(File_navigation.filter, 1, byte_offset-1) + File_navigation.index = 1 + File_navigation.candidates = source.file_navigator_candidates() elseif chord == 'left' then if File_navigation.index > 1 then File_navigation.index = File_navigation.index-1 @@ -243,3 +280,8 @@ function file_index(fy, fx, fwidth) log_end('file index') return best_guess end + +function textinput_on_file_navigator(t) + File_navigation.filter = File_navigation.filter..t + File_navigation.candidates = source.file_navigator_candidates() +end diff --git a/source.lua b/source.lua index 69b2d4f..6dd6d1d 100644 --- a/source.lua +++ b/source.lua @@ -11,7 +11,7 @@ function source.initialize_globals() Focus = 'edit' Show_file_navigator = false File_navigation = { - candidates = { + all_candidates = { 'main', 'run', 'run_tests', @@ -45,7 +45,9 @@ function source.initialize_globals() 'json', }, index = 1, + filter = '', } + File_navigation.candidates = File_navigation.all_candidates -- modified with filter Menu_status_bar_height = 5 + --[[line height in tests]] 15 + 5 @@ -308,6 +310,7 @@ end function source.textinput(t) Cursor_time = 0 -- ensure cursor is visible immediately after it moves if Show_file_navigator then + textinput_on_file_navigator(t) return end if Focus == 'edit' then -- cgit 1.4.1-2-gfad0 From cf227f9031a6b8a9186b534bc51425655a7e0970 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 18 Sep 2022 01:54:32 -0700 Subject: delete a duplicate filename candidate --- source.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/source.lua b/source.lua index 6dd6d1d..dadf4a0 100644 --- a/source.lua +++ b/source.lua @@ -12,7 +12,6 @@ function source.initialize_globals() Show_file_navigator = false File_navigation = { all_candidates = { - 'main', 'run', 'run_tests', 'log', -- cgit 1.4.1-2-gfad0