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 -01-20 01:43:40 +0100 readme: improved' href='/akspecs/ranger/commit/README?h=v1.2.1&id=78a7d7628b5ee969ba47b440f287af02729fd827'>78a7d762 ^
ad3c9818 ^
bd088c49 ^
ad3c9818 ^
78a7d762 ^
cfcfd885 ^





712aa449
0a32b684 ^
cfcfd885 ^
712aa449
4ea0f69a ^


712aa449
0a32b684 ^


2144cf26 ^
36e4e71e ^

4ea0f69a ^

36e4e71e ^




78a7d762 ^
36e4e71e ^

78a7d762 ^
36e4e71e ^


4ea0f69a ^

36e4e71e ^
bd088c49 ^
36e4e71e ^
0a32b684 ^
36e4e71e ^

f6ae504c ^
4ea0f69a ^

0a32b684 ^

4ea0f69a ^
0a32b684 ^
4ea0f69a ^


0a32b684 ^

4ea0f69a ^



36e4e71e ^
7582555b ^
36e4e71e ^
7582555b ^








36e4e71e ^
4ea0f69a ^


36e4e71e ^




4ea0f69a ^

36e4e71e ^



f6ae504c ^
4ea0f69a ^
36e4e71e ^

4ea0f69a ^

36e4e71e ^






4ea0f69a ^

306c76d8 ^






b6aff4c3 ^

306c76d8 ^
4ea0f69a ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124