run script on startup; new button to switch to source editor

This commit is contained in:
Kartik K. Agaram 2023-12-31 21:45:12 -08:00
parent a2c099a0c9
commit 694a148043
7 changed files with 57 additions and 27 deletions

View File

@ -19,4 +19,5 @@ on.initialize = function()
Current_pane_index = 1
Current_pane = Panes[Current_pane_index]
end
run_app()
end

View File

@ -2,26 +2,7 @@ run_button = function(x, y)
styled_button('run', x,y,
function()
Show_menu = nil
-- ## run: initialize
clear_handlers()
local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
edit.clear(Current_pane.output_editor_state)
print = print_to_output
-- ## run
local error = eval_all()
-- ## run: save some stuff, clean up the rest
if error == nil then
Show_code = nil
else
print = Real_print
clear_handlers()
-- could be either output or error
table.insert(Current_pane.output_editor_state.lines, {data=tostring(error)})
end
if #Current_pane.output_editor_state.lines == 0 then
table.insert(Current_pane.output_editor_state.lines, {data=''})
end
Text.redraw_all(Current_pane.output_editor_state)
run_app()
end)
local w = App.width('run')+10
return x+w+10, y

View File

@ -5,6 +5,5 @@ send_errors_to_output = function(err)
Current_pane.output_editor_state.cursor1 = {line=#Current_pane.output_editor_state.lines, pos=1}
Text.redraw_all(Current_pane.output_editor_state)
Text.insert_text(Current_pane.output_editor_state, error_with_callstack)
clear_handlers()
Show_code = true
stop_app()
end

21
0160-run_app Normal file
View File

@ -0,0 +1,21 @@
run_app = function()
-- ## run: initialize
clear_handlers()
edit.clear(Current_pane.output_editor_state)
print = print_to_output
-- ## run
local error = eval_all()
-- ## run: save some stuff, clean up the rest
if error == nil then
Show_code = nil
else
print = Real_print
clear_handlers()
-- could be either output or error
table.insert(Current_pane.output_editor_state.lines, {data=tostring(error)})
end
if #Current_pane.output_editor_state.lines == 0 then
table.insert(Current_pane.output_editor_state.lines, {data=''})
end
Text.redraw_all(Current_pane.output_editor_state)
end

4
0161-stop_app Normal file
View File

@ -0,0 +1,4 @@
stop_app = function()
clear_handlers()
Show_code = true
end

View File

@ -6,6 +6,13 @@
-- adjust zoom based on two-finger touch (touchscreen only)
function car.draw()
color(0, 0.6,0.6)
line(Safe_width-120, 0, Safe_width-120, 40)
g.setFont(Font)
local s = App.width('exit')
line(Safe_width-120, 40, Safe_width-s-20, 40)
line(Safe_width-s-20, 40, Safe_width-s-20, 110)
line(Safe_width-s-20, 110, Safe_width+100, 110)
for _,w in ipairs(widgets) do w.draw() end
draw_hud()
end

View File

@ -1,15 +1,32 @@
widgets = {}
-- button to invoke add_editor
-- button to add a text box
table.insert(widgets, {
draw = function()
color(0, 0.6,0.6)
rect('line', Safe_width-65, Menu_bottom+5, 30,30, 5)
line(Safe_width-60, Menu_bottom+20, Safe_width-40, Menu_bottom+20)
line(Safe_width-50, Menu_bottom+10, Safe_width-50, Menu_bottom+30)
rect('line', Safe_width-115, 5, 30,30, 5)
line(Safe_width-110, 20, Safe_width-90, 20)
line(Safe_width-100, 10, Safe_width-100, 30)
end,
ispress = function(x2,y2)
return x2 >= Safe_width-65 and y2 <= Menu_bottom+35
return x2 >= Safe_width-120 and x2 <= Safe_width-85 and y2 <= 40
end,
press = add_editor,
})
-- button to stop the app and return to the source editor
table.insert(widgets, {
draw = function()
color(0, 0.6,0.6)
g.setFont(Font)
local s = App.width('exit')
rect('line', Safe_width-s-15, 75, s+10,30, 5)
g.print('exit', Safe_width-s-10, 80)
end,
ispress = function(x2,y2)
g.setFont(Font)
local s = App.width('exit')
return x2 >= Safe_width-s-15 and y2 >= 75 and y2 <= 105
end,
press = stop_app,
})