running `print` now appends to output editor
This commit is contained in:
parent
5a998feca7
commit
20f95bc766
|
@ -2,33 +2,7 @@ draw_menu = function()
|
|||
App.color(Menu_background)
|
||||
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_bottom)
|
||||
-- main buttons
|
||||
button(Global_state, 'run', {x=Menu_left+5, y=Menu_top+5, w=App.width('Run')+10, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||
icon = function(p)
|
||||
App.color(Normal_color)
|
||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||
love.graphics.print('Run', p.x+5,p.y+2)
|
||||
end,
|
||||
onpress1 = function()
|
||||
print('run')
|
||||
local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
|
||||
Current_pane.canvas = love.graphics.newCanvas()
|
||||
love.graphics.setCanvas(Current_pane.canvas)
|
||||
love.graphics.push('all')
|
||||
love.graphics.setBackgroundColor(1,1,1)
|
||||
love.graphics.setColor(0,0,0)
|
||||
local status, result = live.eval(buf)
|
||||
print(status, result)
|
||||
if result then
|
||||
-- could be either output or error
|
||||
Current_pane.output_editor_state.lines = {
|
||||
{data=tostring(result)},
|
||||
}
|
||||
Text.redraw_all(Current_pane.output_editor_state)
|
||||
end
|
||||
love.graphics.pop()
|
||||
love.graphics.setCanvas()
|
||||
end,
|
||||
})
|
||||
run_button()
|
||||
-- settings button on right
|
||||
local w = App.width('settings')
|
||||
button(Global_state, 'settings', {x=Safe_width-w-10-5, y=Menu_top+5, w=w+10, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
print_to_output = function(...)
|
||||
local line = table.concat(map({...}, tostring), ' ')
|
||||
table.insert(Current_pane.output_editor_state.lines,
|
||||
{data=line})
|
||||
end
|
|
@ -0,0 +1,37 @@
|
|||
run_button = function()
|
||||
button(Global_state, 'run', {x=Menu_left+5, y=Menu_top+5, w=App.width('Run')+10, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||
icon = function(p)
|
||||
App.color(Normal_color)
|
||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||
love.graphics.print('Run', p.x+5,p.y+2)
|
||||
end,
|
||||
onpress1 = function()
|
||||
-- ## run: initialize
|
||||
local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
|
||||
Current_pane.canvas = love.graphics.newCanvas()
|
||||
love.graphics.setCanvas(Current_pane.canvas)
|
||||
love.graphics.push('all')
|
||||
love.graphics.setBackgroundColor(1,1,1)
|
||||
love.graphics.setColor(0,0,0)
|
||||
Current_pane.output_editor_state.lines = {}
|
||||
Text.redraw_all(Current_pane.output_editor_state)
|
||||
local real_print = print
|
||||
print = print_to_output
|
||||
-- ## run
|
||||
local status, result = live.eval(buf)
|
||||
-- ## run: save some stuff, clean up the rest
|
||||
print = real_print
|
||||
print(status, result)
|
||||
if result then
|
||||
-- could be either output or error
|
||||
table.insert(Current_pane.output_editor_state.lines, {data=tostring(result)})
|
||||
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)
|
||||
love.graphics.pop()
|
||||
love.graphics.setCanvas()
|
||||
end,
|
||||
})
|
||||
end
|
Loading…
Reference in New Issue