running `print` now appends to output editor
Dependencies
- [2]
VAVXKWZVaggregate global state inside a 'pane' object - [3]
6RYGW5H3bugfix: output border color - [4]
Z5M23NTKimplement second, 'output' editor - [5]
5RUFNRJOstart of the visual skeleton - [6]
WR2WMEPEimplement 'Run' button - [7]
PRE6XPRNresponsively increase/decrease font height - [*]
R5QXEHUIsomebody stop me
Change contents
- file addition: 0051-run_button[9.2]
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: initializelocal 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 = printprint = print_to_output-- ## runlocal status, result = live.eval(buf)-- ## run: save some stuff, clean up the restprint = real_printprint(status, result)if result then-- could be either output or errortable.insert(Current_pane.output_editor_state.lines, {data=tostring(result)})endif #Current_pane.output_editor_state.lines == 0 thentable.insert(Current_pane.output_editor_state.lines, {data=''})endText.redraw_all(Current_pane.output_editor_state)love.graphics.pop()love.graphics.setCanvas()end,})end - file addition: 0050-print_to_output[9.2]
print_to_output = function(...)local line = table.concat(map({...}, tostring), ' ')table.insert(Current_pane.output_editor_state.lines,{data=line})end - replacement in 0021-draw_menu at line 5[3.763]→[2.1427:1550](∅→∅),[3.886]→[3.948:969](∅→∅),[2.1550]→[3.948:969](∅→∅),[3.948]→[3.948:969](∅→∅),[3.969]→[3.138:165](∅→∅),[3.165]→[3.887:945](∅→∅),[3.995]→[3.887:945](∅→∅),[3.945]→[3.995:1085](∅→∅),[3.995]→[3.995:1085](∅→∅),[3.1085]→[2.1551:1759](∅→∅),[2.1759]→[3.644:790](∅→∅),[3.644]→[3.644:790](∅→∅),[3.790]→[3.1576:1658](∅→∅),[3.1658]→[2.1760:1807](∅→∅),[2.1807]→[3.1692:1728](∅→∅),[3.1692]→[3.1692:1728](∅→∅),[3.1728]→[2.1808:1862](∅→∅),[3.1769]→[3.830:889](∅→∅),[2.1862]→[3.830:889](∅→∅),[3.830]→[3.830:889](∅→∅),[3.889]→[3.946:957](∅→∅),[3.1085]→[3.946:957](∅→∅)
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 errorCurrent_pane.output_editor_state.lines = {{data=tostring(result)},}Text.redraw_all(Current_pane.output_editor_state)endlove.graphics.pop()love.graphics.setCanvas()end,})run_button()