From 30fcdb46b372d8b90a68c0f695fd2860af9ca288 Mon Sep 17 00:00:00 2001 From: aldum Date: Tue, 10 Feb 2026 15:39:35 +0100 Subject: [PATCH 01/13] fix(turtle): use default font #112 --- src/examples/turtle/drawing.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/examples/turtle/drawing.lua b/src/examples/turtle/drawing.lua index 5c5a2077..fb586f5e 100644 --- a/src/examples/turtle/drawing.lua +++ b/src/examples/turtle/drawing.lua @@ -1,6 +1,5 @@ gfx = love.graphics -font = gfx.newFont() bg_color = Color.black body_color = Color.green limb_color = body_color + Color.bright @@ -71,15 +70,16 @@ function drawTurtle(x, y) end function drawHelp() + local x = 15 gfx.setColor(Color[Color.white]) - gfx.print("Press [I] to open console", 20, 20) - local help = "Enter 'forward', 'back', 'left', or 'right'" .. + gfx.print("Press [I] to open console", x, 20) + local help = "Enter 'forward', 'back', 'left', or 'right' " .. "to move the turtle!" - gfx.print(help, 20, 50) + gfx.print(help, x, 50) end function drawDebuginfo() gfx.setColor(Color[debug_color]) local dt = string.format("Turtle position: (%d, %d)", tx, ty) - gfx.print(dt, width - 200, 20) + gfx.print(dt, width - 500, 80) end From c08ee51cd58b629f4d53f4b1efdcd1dcffebcc21 Mon Sep 17 00:00:00 2001 From: aldum Date: Tue, 10 Feb 2026 15:39:35 +0100 Subject: [PATCH 02/13] reafactor: clean up readlines/readfile #113 --- src/controller/consoleController.lua | 20 ++++++++++++++++++-- src/model/project/project.lua | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/controller/consoleController.lua b/src/controller/consoleController.lua index ee266acd..33a0f150 100644 --- a/src/controller/consoleController.lua +++ b/src/controller/consoleController.lua @@ -135,7 +135,7 @@ end --- @private --- @param name string ---- @return string[]? +--- @return string? function ConsoleController:_readfile(name) local PS = self.model.projects local p = PS.current @@ -147,6 +147,16 @@ function ConsoleController:_readfile(name) end end +--- @private +--- @param name string +--- @return string[]? +function ConsoleController:_readlines(name) + local s = self:_readfile(name) + if s then + return string.lines(s) + end +end + --- @private --- @param name string --- @param content string[] @@ -325,11 +335,17 @@ function ConsoleController.prepare_env(cc) end --- @param name string - --- @return string[]? + --- @return string? prepared.readfile = function(name) return check_open_pr(cc._readfile, cc, name) end + --- @param name string + --- @return string[]? + prepared.readlines = function(name) + return check_open_pr(cc._readlines, cc, name) + end + --- @param name string --- @param content string[] prepared.writefile = function(name, content) diff --git a/src/model/project/project.lua b/src/model/project/project.lua index 97afdb1f..9d4a0777 100644 --- a/src/model/project/project.lua +++ b/src/model/project/project.lua @@ -89,7 +89,7 @@ end --- @param name string --- @return boolean success ---- @return string?|string result|errmsg +--- @return string? result|errmsg function Project:readfile(name) local fp if self.play then From e23efd7832c3f7f73d46fa15d8830b95e11d77f7 Mon Sep 17 00:00:00 2001 From: aldum Date: Tue, 10 Feb 2026 15:39:35 +0100 Subject: [PATCH 03/13] doc: readfile/readlines #113 --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c67ca98f..7bc3cf34 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,11 @@ contents. - `readfile(file)` - Open _file_ and display it's contents. + Open _file_ and return it's contents as a single string. + +- `readlines(file)` + + Open _file_ and return a string table of it's lines. - `writefile(file, content)` From fbc0dc917c40f99bb641f91d69fea532cdd6322a Mon Sep 17 00:00:00 2001 From: aldum Date: Tue, 10 Feb 2026 15:39:35 +0100 Subject: [PATCH 04/13] fix: make readline/readfile available in project #113 --- src/controller/consoleController.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/controller/consoleController.lua b/src/controller/consoleController.lua index 33a0f150..421e3031 100644 --- a/src/controller/consoleController.lua +++ b/src/controller/consoleController.lua @@ -435,7 +435,21 @@ function ConsoleController.prepare_project_env(cc) end -- project_env.require = function(name) -- return project_require(name, 'run') - -- end + -- end + + --- @param name string + --- @return string? + project_env.readfile = function(name) + --- @diagnostic disable-next-line: invisible + return cc:_readfile(name) + end + + --- @param name string + --- @return string[]? + project_env.readlines = function(name) + --- @diagnostic disable-next-line: invisible + return cc:_readlines(name) + end --- @param msg string? project_env.pause = function(msg) From 26e4e98add0a1f585f10fb7eae565ce6f4a642a1 Mon Sep 17 00:00:00 2001 From: aldum Date: Tue, 10 Feb 2026 15:39:35 +0100 Subject: [PATCH 05/13] refactor: writefile #112 --- src/controller/consoleController.lua | 58 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/controller/consoleController.lua b/src/controller/consoleController.lua index 421e3031..f5c1ad56 100644 --- a/src/controller/consoleController.lua +++ b/src/controller/consoleController.lua @@ -169,6 +169,22 @@ function ConsoleController:_writefile(name, content) return p:writefile(name, text) end +function ConsoleController:writefile(name, content) + local P = self.model.projects + local p = P.current + local fpath = p:get_path(name) + local ex = FS.exists(fpath) + if ex then + -- TODO: confirm overwrite + end + local ok, err = self:_writefile(name, content) + if ok then + print(name .. ' written') + else + print(err) + end +end + function ConsoleController:run_project(name) if love.state.app_state == 'inspect' or love.state.app_state == 'running' @@ -349,20 +365,7 @@ function ConsoleController.prepare_env(cc) --- @param name string --- @param content string[] prepared.writefile = function(name, content) - return check_open_pr(function() - local p = P.current - local fpath = p:get_path(name) - local ex = FS.exists(fpath) - if ex then - -- TODO: confirm overwrite - end - local ok, err = cc:_writefile(name, content) - if ok then - print(name .. ' written') - else - print(err) - end - end) + return check_open_pr(cc.writefile, cc, name, content) end --- @param name string @@ -435,22 +438,28 @@ function ConsoleController.prepare_project_env(cc) end -- project_env.require = function(name) -- return project_require(name, 'run') - -- end + -- end --- @param name string --- @return string? - project_env.readfile = function(name) - --- @diagnostic disable-next-line: invisible - return cc:_readfile(name) - end + project_env.readfile = function(name) + --- @diagnostic disable-next-line: invisible + return cc:_readfile(name) + end --- @param name string --- @return string[]? - project_env.readlines = function(name) + project_env.readlines = function(name) --- @diagnostic disable-next-line: invisible return cc:_readlines(name) end + --- @param name string + --- @param content string[] + project_env.writefile = function(name, content) + return cc:writefile(name, content) + end + --- @param msg string? project_env.pause = function(msg) cc:suspend_run(msg) @@ -841,15 +850,6 @@ function ConsoleController:finish_edit() self.editor:close() local ok = true local errs = {} - -- local bfs = self.editor:close() - -- for _, bc in ipairs(bfs) do - -- local name, newcontent = bc.name, bc.content - -- local bok, err = self:_writefile(name, newcontent) - -- if not bok then - -- ok = false - -- table.insert(errs, err) - -- end - -- end if ok then love.state.app_state = love.state.prev_state love.state.prev_state = nil From 63ec538dddbdb0f8bbff19d091389ccec9814730 Mon Sep 17 00:00:00 2001 From: aldum Date: Tue, 10 Feb 2026 15:39:35 +0100 Subject: [PATCH 06/13] chore: add project env globals --- .luarc.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.luarc.json b/.luarc.json index ccc8cc99..eef8e203 100644 --- a/.luarc.json +++ b/.luarc.json @@ -19,10 +19,14 @@ "stop", "pause", "continue", + "readfile", + "readlines", + "writefile", // luautils "prequire", "codeload", "error_test", + "parse_int", // end of array "" ], From 66b77516f034a72afd47804ad69090cb4ad5f8c4 Mon Sep 17 00:00:00 2001 From: aldum Date: Wed, 18 Feb 2026 12:42:01 +0100 Subject: [PATCH 07/13] feat(tixy): replace return with assignment #118 --- src/examples/tixy/README.md | 5 ++- src/examples/tixy/examples.lua | 72 +++++++++++++++++----------------- src/examples/tixy/main.lua | 5 ++- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/examples/tixy/README.md b/src/examples/tixy/README.md index 77dca387..042b68f9 100644 --- a/src/examples/tixy/README.md +++ b/src/examples/tixy/README.md @@ -54,7 +54,7 @@ First, to take some string and if it's valid code, turn it into a function, we u local f = loadstring(code) ``` -Should there be some syntactic problem, we will get `nil` back, so the next stop is checking for that. In our case, the input already validates, so we should not find ourselves on the unhappy side of this. +Should there be some syntactic problem, we will get `nil` back, so the next stop is checking for it. In our case, the input already validates, so we should not find ourselves on the unhappy side of this. Next, set up the environment the function will run in, which should be `_G`, the same environment we prepared with easy access to math functions and bit operations. @@ -72,7 +72,8 @@ Here's what the actual function looks like: ```lua function f() return function(t, i, x, y) - -- body + -- r = ... -- function body + return r end end ``` diff --git a/src/examples/tixy/examples.lua b/src/examples/tixy/examples.lua index 618eb7f5..d14a2cbc 100644 --- a/src/examples/tixy/examples.lua +++ b/src/examples/tixy/examples.lua @@ -2,100 +2,100 @@ local examples = {} function example(c, l) table.insert(examples, { - code = c, + code = "r = " .. c, legend = l }) end example( - "return b2n(math.random() < 0.1)", + "b2n(math.random() < 0.1)", "for every dot return 0 or 1 \nto change the visibility" ) example( - "return math.random()", + "math.random()", "use a float between 0 and 1 \nto define the size" ) example( - "return math.sin(t)", + "math.sin(t)", "parameter `t` is \nthe time in seconds" ) example( - "return i / 256", + "i / 256", "param `i` is the index \nof the dot (0..255)" ) example( - "return x / count", + "x / count", "`x` is the column index\n from 0 to 15" ) -example("return y / count", "`y` is the row\n also from 0 to 15") +example("y / count", "`y` is the row\n also from 0 to 15") example( - "return y - 7.5", + "y - 7.5", "positive numbers are white,\nnegatives are red" ) -example("return y - t", "use the time\nto animate values") +example("y - t", "use the time\nto animate values") example( - "return y - 4 * t", + "y - 4 * t", "multiply the time\nto change the speed" ) example( - "return ({1, 0, -1})[i % 3 + 1]", + "({1, 0, -1})[i % 3 + 1]", "create patterns using \ndifferent color" ) example( - "return sin(t - sqrt((x - 7.5)^2 + (y-6)^2) )", + "sin(t - sqrt((x - 7.5)^2 + (y-6)^2) )", "skip `math.` to use methods \nand props like `sin` or `pi`" ) -example("return sin(y/8 + t)", "more examples ...") -example("return y - x", "simple triangle") +example("sin(y/8 + t)", "more examples ...") +example("y - x", "simple triangle") example( - "return b2n( (y > x) and (14 - x < y) )", + "b2n( (y > x) and (14 - x < y) )", "quarter triangle" ) -example("return i % 4 - y % 4", "pattern") +example("i % 4 - y % 4", "pattern") example( - "return b2n(n2b(math.fmod(x, 4)) and n2b(math.fmod(y, 4)))", + "b2n(n2b(math.fmod(x, 4)) and n2b(math.fmod(y, 4)))", "grid" ) -example("return b2n( x>3 and y>3 and x<12 and y<12 )", "square") +example("b2n( x>3 and y>3 and x<12 and y<12 )", "square") example( - "return -1 * b2n( x>t and y>t and x<15-t and y<15-t )", + "-1 * b2n( x>t and y>t and x<15-t and y<15-t )", "animated square" ) -example("return (y-6) * (x-6)", "mondrian squares") +example("(y-6) * (x-6)", "mondrian squares") example( - "return floor(y - 4 * t) * floor(x - 2 - t)", + "floor(y - 4 * t) * floor(x - 2 - t)", "moving cross" ) -example("return band(4 * t, i, x, y)", "sierpinski") +example("band(4 * t, i, x, y)", "sierpinski") example( - "return y == 8 and band(t * 10, lshift(1, x)) or 0", + "y == 8 and band(t * 10, lshift(1, x)) or 0", "binary clock" ) -example("return random() * 2 - 1", "random noise") -example("return sin(i ^ 2)", "static smooth noise") -example("return cos(t + i + x * y)", "animated smooth noise") -example("return sin(x/2) - sin(x-t) - y+6", "waves") +example("random() * 2 - 1", "random noise") +example("sin(i ^ 2)", "static smooth noise") +example("cos(t + i + x * y)", "animated smooth noise") +example("sin(x/2) - sin(x-t) - y+6", "waves") example( - "return (x-8) * (y-8) - sin(t) * 64", + "(x-8) * (y-8) - sin(t) * 64", "bloop bloop bloop" ) example( - "return -.4 / (hypot(x - t%10, y - t%8) - t%2 * 9)", + "-.4 / (hypot(x - t%10, y - t%8) - t%2 * 9)", "fireworks" ) -example("return sin(t - hypot(x, y))", "ripples") +example("sin(t - hypot(x, y))", "ripples") example( - "return band( ({5463,2194,2386})[ band(y+t*9, 7) ]" .. + "band( ({5463,2194,2386})[ band(y+t*9, 7) ]" .. " or 0, lshift(1, x - 1) )", "scrolling TIXY") -example("return (x-y) - sin(t) * 16", "wipe") -example("return (x-y)/24 - sin(t)", "soft wipe") -example("return sin(t*5) * tan(t*7)", "disco") +example("(x-y) - sin(t) * 16", "wipe") +example("(x-y)/24 - sin(t)", "soft wipe") +example("sin(t*5) * tan(t*7)", "disco") example( - "return (x-(count/2))^2 + (y-(count/2))^2 - 15*cos(pi/4)", + "(x-(count/2))^2 + (y-(count/2))^2 - 15*cos(pi/4)", "日本" ) example( - "return (x-5)^2 + (y-5)^2 - 99*sin(t)", + "(x-5)^2 + (y-5)^2 - 99*sin(t)", "create your own!" ) diff --git a/src/examples/tixy/main.lua b/src/examples/tixy/main.lua index 993a50fb..8cdf94cc 100644 --- a/src/examples/tixy/main.lua +++ b/src/examples/tixy/main.lua @@ -90,7 +90,10 @@ function tixy(t, i, x, y) end function setupTixy() - local code = "return function(t, i, x, y)\n" .. body .. " end" + local code = "return function(t, i, x, y)\n" .. + " " .. body .. + " return r\n" .. + "end" local f = loadstring(code) if f then setfenv(f, _G) From 35984db2aa6c6fb3d4c4423f04390174e0941ea6 Mon Sep 17 00:00:00 2001 From: aldum Date: Sun, 25 Jan 2026 14:22:30 +0100 Subject: [PATCH 08/13] feat: make compy.terminal available in project_env #116 --- src/controller/consoleController.lua | 48 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/controller/consoleController.lua b/src/controller/consoleController.lua index f5c1ad56..3d1c37b4 100644 --- a/src/controller/consoleController.lua +++ b/src/controller/consoleController.lua @@ -263,6 +263,24 @@ end -- Set up audio table local compy_audio = require("util.audio") +local get_compy_terminal = function(terminal) + return { + --- @param x number + --- @param y number + gotoxy = function(x, y) + return terminal:move_to(x, y) + end, + show_cursor = function() + return terminal:show_cursor() + end, + hide_cursor = function() + return terminal:hide_cursor() + end, + clear = function() + return terminal:clear() + end + } +end function ConsoleController.prepare_env(cc) local prepared = cc.main_env @@ -379,22 +397,7 @@ function ConsoleController.prepare_env(cc) local terminal = cc.model.output.terminal local compy_namespace = { - terminal = { - --- @param x number - --- @param y number - gotoxy = function(x, y) - return terminal:move_to(x, y) - end, - show_cursor = function() - return terminal:show_cursor() - end, - hide_cursor = function() - return terminal:hide_cursor() - end, - clear = function() - return terminal:clear() - end - }, + terminal = get_compy_terminal(terminal), audio = compy_audio, } prepared.compy = compy_namespace @@ -424,11 +427,6 @@ function ConsoleController.prepare_project_env(cc) local cfg = cc.model.cfg ---@type table local project_env = cc:get_pre_env_c() - project_env.gfx = love.graphics - - project_env.compy = { - audio = compy_audio - } project_env.require = function(name) return project_require(name) @@ -558,6 +556,14 @@ function ConsoleController.prepare_project_env(cc) return cc:edit(name) end + project_env.gfx = love.graphics + + project_env.compy = { + audio = compy_audio, + terminal = get_compy_terminal(cc.model.output.terminal), + text_input = input_text + } + project_env.eval = LANG.eval project_env.print_eval = LANG.print_eval From 4bf9d41204115eaf1fbf88e645074dced24c6966 Mon Sep 17 00:00:00 2001 From: aldum Date: Sun, 25 Jan 2026 14:22:30 +0100 Subject: [PATCH 09/13] feat: add global utilities `noop` and `identity` functions --- .luarc.json | 3 +++ src/util/lua.lua | 2 ++ 2 files changed, 5 insertions(+) diff --git a/.luarc.json b/.luarc.json index eef8e203..b8b6519a 100644 --- a/.luarc.json +++ b/.luarc.json @@ -3,6 +3,7 @@ // LOVE / libs "utf8", "lfs", + "compy", // "pending", // busted "describe", @@ -23,6 +24,8 @@ "readlines", "writefile", // luautils + "noop", + "identity", "prequire", "codeload", "error_test", diff --git a/src/util/lua.lua b/src/util/lua.lua index 35407a05..299ff7a4 100644 --- a/src/util/lua.lua +++ b/src/util/lua.lua @@ -24,6 +24,8 @@ local codeload = function(code, env) end local t = { + noop = function() end, + identity = function(a) return a end, prequire = prequire, error_test = function() if love and love.DEBUG then From b88d1e8d6c2b701d350daa63694b00cd68ec58c0 Mon Sep 17 00:00:00 2001 From: aldum Date: Sat, 21 Feb 2026 02:05:24 +0100 Subject: [PATCH 10/13] feat: draw a thicker cursor on pos 1 #117 --- src/view/input/userInputView.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/view/input/userInputView.lua b/src/view/input/userInputView.lua index f5ffe90a..4e6d8128 100644 --- a/src/view/input/userInputView.lua +++ b/src/view/input/userInputView.lua @@ -47,6 +47,9 @@ end --- there either is no next line yet, or it would look the --- same as if it was at the start of the next. --- Hence, the overflow phantom line. +--- @param w integer +--- @param text string[] +--- @param cursor Cursor local calc_overflow = function(w, text, cursor) local cl, cc = cursor.l, cursor.c local acc = cc - 1 @@ -76,7 +79,6 @@ function UserInputView:render_input(input, status) local fh = cfg.fh local fw = cfg.fw - local h = 0 local drawableWidth = cfg.drawableWidth local w = cfg.drawableChars -- drawtest hack @@ -122,6 +124,9 @@ function UserInputView:render_input(input, status) gfx.push('all') gfx.setColor(cf_colors.input.cursor) gfx.print('|', x, ch) + if x_offset == 0 then + gfx.print('|', x + 4, ch) + end gfx.pop() end From c8ca7347520c56df80291de1840705a6fcc5defa Mon Sep 17 00:00:00 2001 From: aldum Date: Tue, 24 Feb 2026 18:20:14 +0100 Subject: [PATCH 11/13] refactor(doubleclick): move handlers #120 --- src/controller/consoleController.lua | 16 ++++++++++++++++ src/controller/controller.lua | 21 +++++++++++---------- src/examples/paint/README.md | 4 ++-- src/examples/paint/main.lua | 4 ++-- src/love_types.lua | 3 --- src/types.lua | 7 +++++++ 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/controller/consoleController.lua b/src/controller/consoleController.lua index 3d1c37b4..8f78cc8d 100644 --- a/src/controller/consoleController.lua +++ b/src/controller/consoleController.lua @@ -185,6 +185,22 @@ function ConsoleController:writefile(name, content) end end +--- @param name string +--- @return function? handler +function ConsoleController:get_compy_handler(name) + local env = self:get_project_env() + if not env then return end + local active_compy = env['compy'] + if not active_compy then return end + local handler = active_compy[name] + if not handler then + return + else + return handler + end +end + +--- @param name string function ConsoleController:run_project(name) if love.state.app_state == 'inspect' or love.state.app_state == 'running' diff --git a/src/controller/controller.lua b/src/controller/controller.lua index 1ec84949..4bccc0b9 100644 --- a/src/controller/controller.lua +++ b/src/controller/controller.lua @@ -123,7 +123,7 @@ local set_handlers = function(userlove, C) end end -local click_delay = 0.2 +local click_delay = 0.4 local drift_tolerance = 2.5 local click_count = 0 @@ -351,8 +351,8 @@ Controller = { -- update -- -------------- --- @private - --- @param C ConsoleController - set_love_update = function(C) + --- @param CC ConsoleController + set_love_update = function(CC) local function update(dt) if love.PROFILE then Prof.update() @@ -363,7 +363,7 @@ Controller = { if click_timer <= 0 then if click_count == 1 then -- single click confirmed after delay - local handler = love.singleclick + local handler = CC:get_compy_handler('singleclick') if handler then local x, y = love.mouse.getPosition() local cur = { x = x, y = y } @@ -373,7 +373,8 @@ Controller = { end elseif click_count >= 2 then -- double click detected - local dbl_handler = love.doubleclick + local dbl_handler = + CC:get_compy_handler('doubleclick') if dbl_handler then local x, y = love.mouse.getPosition() local cur = { x = x, y = y } @@ -391,7 +392,7 @@ Controller = { local draw = function() if ldr then gfx.push('all') - wrap(ldr, C) + wrap(ldr, CC) gfx.pop() end local ui = get_user_input() @@ -403,20 +404,20 @@ Controller = { View.prev_draw = draw love.draw = draw end - C:pass_time(dt) + CC:pass_time(dt) local uup = Controller._userhandlers.update if user_update and uup then - C:use_canvas(function() - wrap(uup, C, dt) + CC:use_canvas(function() + wrap(uup, CC, dt) end) end if love.state.app_state == 'snapshot' then gfx.captureScreenshot(function(img) local snap = gfx.newImage(img) View.snapshot = snap - C:suspend() + CC:suspend() end) end diff --git a/src/examples/paint/README.md b/src/examples/paint/README.md index bfde8aa5..cd3537c7 100644 --- a/src/examples/paint/README.md +++ b/src/examples/paint/README.md @@ -192,11 +192,11 @@ Double clicks/taps are a workable solution, but there is a problem: detecting th To solve for this, we created custom handlers for single and double clicks: ```lua -function love.singleclick(x, y) +function compy.singleclick(x, y) point(x, y, 1) end -function love.doubleclick(x, y) +function compy.doubleclick(x, y) point(x, y, 2) end ``` diff --git a/src/examples/paint/main.lua b/src/examples/paint/main.lua index 01e4ef7d..96e5d3be 100644 --- a/src/examples/paint/main.lua +++ b/src/examples/paint/main.lua @@ -353,11 +353,11 @@ function point(x, y, btn) end end -function love.singleclick(x, y) +function compy.singleclick(x, y) point(x, y, 1) end -function love.doubleclick(x, y) +function compy.doubleclick(x, y) point(x, y, 2) end diff --git a/src/love_types.lua b/src/love_types.lua index b7b9779b..c907d1bc 100644 --- a/src/love_types.lua +++ b/src/love_types.lua @@ -13,6 +13,3 @@ --- @field touchmoved function? --- @field touchpressed function? --- @field touchreleased function? ---- bespoke ---- @field singleclick function? ---- @field doubleclick function? diff --git a/src/types.lua b/src/types.lua index e53f9f24..d770294e 100644 --- a/src/types.lua +++ b/src/types.lua @@ -182,3 +182,10 @@ --- @field n_frames integer --- @field n_rows integer --- @field fpsc FPSC + +--- @class Compy +--- @field singleclick function? +--- @field doubleclick function? +--- @field terminal table? +--- @field audio table? +--- @field font table? From ab213e663fdb215ae6bb48dff56b63d9ad146a2e Mon Sep 17 00:00:00 2001 From: aldum Date: Fri, 6 Mar 2026 22:51:50 +0100 Subject: [PATCH 12/13] fix: wrap double/singleclick handlers --- src/controller/consoleController.lua | 16 ++++++++++++++++ src/controller/controller.lua | 9 ++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/controller/consoleController.lua b/src/controller/consoleController.lua index 8f78cc8d..4965491f 100644 --- a/src/controller/consoleController.lua +++ b/src/controller/consoleController.lua @@ -185,6 +185,22 @@ function ConsoleController:writefile(name, content) end end +--- Wrap `f` with errhand if passed, and set target canvas +--- @param f function +--- @param errhand function? +--- @return function wrapped_handler +function ConsoleController:wrap_handler(f, errhand) + local eh = errhand or identity + return function(...) + local args = { ... } + self:use_canvas( + function() + return eh(f, self, unpack(args)) + end + ) + end +end + --- @param name string --- @return function? handler function ConsoleController:get_compy_handler(name) diff --git a/src/controller/controller.lua b/src/controller/controller.lua index 4bccc0b9..76de02b8 100644 --- a/src/controller/controller.lua +++ b/src/controller/controller.lua @@ -34,9 +34,6 @@ local _supported = { 'mousepressed', 'mousereleased', 'wheelmoved', - --- custom handlers - 'singleclick', - 'doubleclick', 'touchmoved', 'touchpressed', @@ -365,10 +362,11 @@ Controller = { -- single click confirmed after delay local handler = CC:get_compy_handler('singleclick') if handler then + local h = CC:wrap_handler(handler, wrap) local x, y = love.mouse.getPosition() local cur = { x = x, y = y } if no_drift(click_pos, cur) then - handler(x, y) + h(x, y) end end elseif click_count >= 2 then @@ -376,10 +374,11 @@ Controller = { local dbl_handler = CC:get_compy_handler('doubleclick') if dbl_handler then + local h = CC:wrap_handler(dbl_handler, wrap) local x, y = love.mouse.getPosition() local cur = { x = x, y = y } if no_drift(click_pos, cur) then - dbl_handler(x, y) + h(x, y) end end end From 7c66af2742886816452a6bf04b6fd3c423b69ae5 Mon Sep 17 00:00:00 2001 From: aldum Date: Fri, 20 Feb 2026 12:39:23 +0100 Subject: [PATCH 13/13] fix: terminal.clear resets cursor --- src/controller/consoleController.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controller/consoleController.lua b/src/controller/consoleController.lua index 4965491f..72f91065 100644 --- a/src/controller/consoleController.lua +++ b/src/controller/consoleController.lua @@ -309,6 +309,7 @@ local get_compy_terminal = function(terminal) return terminal:hide_cursor() end, clear = function() + terminal:move_to(1, 1) return terminal:clear() end }