From fdf6f7b5d9d23f37d237eff7c0b4c1646132d921 Mon Sep 17 00:00:00 2001 From: IgorTimofeev Date: Wed, 11 May 2022 20:55:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B2=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D1=83=D1=85?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications/Console.app/Main.lua | 35 ++++++++------------ Applications/Events.app/Icon.pic | Bin 0 -> 153 bytes Applications/Events.app/Main.lua | 52 ++++++++++++++++++++++++++++++ Libraries/System.lua | 39 ++++++++++++++-------- 4 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 Applications/Events.app/Icon.pic create mode 100644 Applications/Events.app/Main.lua diff --git a/Applications/Console.app/Main.lua b/Applications/Console.app/Main.lua index cbd56f3c..89e7310c 100644 --- a/Applications/Console.app/Main.lua +++ b/Applications/Console.app/Main.lua @@ -9,14 +9,14 @@ local text = require("Text") local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 82, 28, 0x000000)) -local disp = window:addChild(GUI.object(2, 4, 1, 1)) +local display = window:addChild(GUI.object(2, 4, 1, 1)) local cursorX, cursorY = 1, 1 local lineFrom = 1 local lines = {} local input = "" -disp.draw = function(disp) - local x, y = disp.x, disp.y +display.draw = function(display) + local x, y = display.x, display.y for i = lineFrom, #lines do screen.drawText(x, y, 0xFFFFFF, lines[i]) y = y + 1 @@ -27,13 +27,13 @@ disp.draw = function(disp) screen.drawText(x + unicode.len(text), y, 0x00A8FF, "┃") end -window.addLine = function(value) - local value = text.wrap(value, disp.width) +window.addLine = function(window, value) + local value = text.wrap(value, display.width) for i = 1, #value do table.insert(lines, value[i]) - if #lines - lineFrom + 1 > disp.height - 1 then + if #lines - lineFrom + 1 > display.height - 1 then lineFrom = lineFrom + 1 end end @@ -53,18 +53,19 @@ window.eventHandler = function(workspace, window, ...) end workspace:draw() + elseif e[1] == "key_down" and GUI.focusedObject == window then -- Return if e[4] == 28 then - window.addLine("> " .. input) + window:addLine("> " .. input) input = "" + -- Backspace elseif e[4] == 14 then input = unicode.sub(input, 1, -2) + -- Printable character elseif not keyboard.isControl(e[3]) then - local char = unicode.char(e[3]) - - input = input .. char + input = input .. unicode.char(e[3]) end workspace:draw() @@ -73,21 +74,13 @@ window.eventHandler = function(workspace, window, ...) overrideWindowEventHandler(workspace, window, ...) end -local overrideWindowRemove = window.remove -window.remove = function(...) - system.consoleWindow = nil - - overrideWindowRemove(...) -end - window.onResize = function(newWidth, newHeight) window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight - disp.width, disp.height = newWidth - 2, newHeight - 3 + display.width, display.height = newWidth - 2, newHeight - 3 end --------------------------------------------------------------------------------- -system.consoleWindow = window - window.onResize(window.width, window.height) -workspace:draw() \ No newline at end of file + +return window \ No newline at end of file diff --git a/Applications/Events.app/Icon.pic b/Applications/Events.app/Icon.pic new file mode 100644 index 0000000000000000000000000000000000000000..4c75319a7a504bc7bf87b127d981cab61432586d GIT binary patch literal 153 zcmeZw_H^T5XJ%kv;3@(V!3>NH%*jB;e+DK7)&i&q>!Sq|7#NuD0l5sHfSA!ANHC=U z36OfGQXm7Qo+SgyV6%fV81sROK~l^hg)AjdVI~EjFi?b display.height then + table.remove(lines, 1) + end + end + + workspace:draw() + end +end + +window.onResize = function(newWidth, newHeight) + window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight + display.width, display.height = newWidth - 2, newHeight - 4 +end + +--------------------------------------------------------------------------------- + +window.onResize(window.width, window.height) +workspace:draw() \ No newline at end of file diff --git a/Libraries/System.lua b/Libraries/System.lua index 4eaddbd7..81e096c6 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -2898,6 +2898,22 @@ function system.addBlurredOrDefaultPanel(container, x, y, width, height) return container:addChild(userSettings.interfaceBlurEnabled and GUI.blurredPanel(x, y, width, height, userSettings.interfaceBlurRadius, 0x0, userSettings.interfaceBlurTransparency) or GUI.panel(x, y, width, height, 0x2D2D2D)) end +function system.addConsoleWindow() + local result, data = loadfile(paths.system.applicationConsole) + + if result then + result, data = xpcall(result, debug.traceback) + + if not result then + GUI.alert(data) + end + + return data + else + GUI.alert(data) + end +end + -------------------------------------------------------------------------------- -- Keeping temporary file's last modified timestamp as boot timestamp @@ -2912,19 +2928,16 @@ end -- Global print() function for debugging _G.print = function(...) if not system.consoleWindow then - local result, data = loadfile(paths.system.applicationConsole) - - if result then - result, data = xpcall(result, debug.traceback) - - if not result then - GUI.alert(data) - return - end - else - GUI.alert(data) - return + system.consoleWindow = system.addConsoleWindow() + + local overrideWindowRemove = system.consoleWindow.remove + system.consoleWindow.remove = function(...) + system.consoleWindow = nil + + overrideWindowRemove(...) end + + workspace:draw() end local args, arg = {...} @@ -2943,7 +2956,7 @@ _G.print = function(...) args = table.concat(args, " ") - system.consoleWindow.addLine(args) + system.consoleWindow:addLine(args) system.consoleWindow:focus() end