(local love _G.love)
(local fennel (require :fennel))
(set [_G.lines _G.input] [[] []])
(fn onValues [xs] (icollect [_ x (ipairs xs) :into _G.lines] x))
(local repl (coroutine.create (partial fennel.repl)))
(coroutine.resume repl {: onValues :readChunk coroutine.yield})
(fn love.textinput [text] (table.insert _G.input text))
(fn pop-input []
(let [text (table.concat _G.input)]
(set _G.input [])
(.. text "\n")))
(fn love.keypressed [key]
(case key
:return (coroutine.resume repl (pop-input))
:backspace (table.remove _G.input)
:escape (love.event.quit)))
(fn love.draw []
(let [(w h) (love.window.getMode)
fh (+ (: (love.graphics.getFont) :getHeight) 12)]
(each [i line (ipairs _G.lines)]
(love.graphics.print line 2 (* i (+ fh 2))))
(love.graphics.line 0 (- h fh 4) w (- h fh 4)) (love.graphics.print (table.concat _G.input) 9 (- h fh))))