diff --git a/Applications/Console.app/Icon.pic b/Applications/Console.app/Icon.pic new file mode 100644 index 00000000..68999e14 Binary files /dev/null and b/Applications/Console.app/Icon.pic differ diff --git a/Applications/Console.app/Localizations/English.lang b/Applications/Console.app/Localizations/English.lang new file mode 100644 index 00000000..dab7151d --- /dev/null +++ b/Applications/Console.app/Localizations/English.lang @@ -0,0 +1,3 @@ +{ + greeting = "Hello, " +} \ No newline at end of file diff --git a/Applications/Console.app/Main.lua b/Applications/Console.app/Main.lua new file mode 100644 index 00000000..1c78180a --- /dev/null +++ b/Applications/Console.app/Main.lua @@ -0,0 +1,87 @@ + +local GUI = require("GUI") +local system = require("System") +local keyboard = require("Keyboard") +local screen = require("Screen") + +--------------------------------------------------------------------------------- + +-- Add a new window to MineOS workspace +local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 82, 28, 0x000000)) + +local disp = 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 + for i = lineFrom, #lines do + screen.drawText(x, y, 0xFFFFFF, lines[i]) + y = y + 1 + end + + local text = "> " .. input + screen.drawText(x, y, 0xFFFFFF, text) + screen.drawText(x + unicode.len(text), y, 0x00A8FF, "┃") +end + +window.addLine = function(line) + table.insert(lines, line) + + if #lines - lineFrom + 1 > disp.height - 1 then + lineFrom = lineFrom + 1 + end +end + +local overrideWindowEventHandler = window.eventHandler +window.eventHandler = function(workspace, window, ...) + local e = {...} + + if e[1] == "scroll" then + lineFrom = lineFrom + (e[5] > 0 and -1 or 1) + + if lineFrom < 1 then + lineFrom = 1 + elseif lineFrom > #lines then + lineFrom = #lines + end + + workspace:draw() + elseif e[1] == "key_down" and GUI.focusedItem == window then + -- Return + if e[4] == 28 then + window.addLine("> " .. input) + input = "" + elseif not keyboard.isControl(e[4]) then + local char = unicode.char(e[3]) + + input = input .. char + end + + workspace:draw() + end + + overrideWindowEventHandler(workspace, window, ...) +end + +-- Create callback function with resizing rules when window changes its' size +window.onResize = function(newWidth, newHeight) + window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight + disp.width, disp.height = newWidth - 2, newHeight - 3 +end + +local overrideWindowRemove = window.remove +window.remove = function(...) + system.consoleWindow = nil + + overrideWindowRemove(...) +end + +--------------------------------------------------------------------------------- + +system.consoleWindow = window + +window.onResize(window.width, window.height) +workspace:draw() diff --git a/Applications/MineCode IDE.app/Main.lua b/Applications/MineCode IDE.app/Main.lua index 2dbce8d6..80dd698b 100755 --- a/Applications/MineCode IDE.app/Main.lua +++ b/Applications/MineCode IDE.app/Main.lua @@ -1252,14 +1252,12 @@ local function find() to = {symbol = ending, line = line}, color = 0xCC9200 } - findStartFrom = line gotoLine(line) - return end else - return + GUI.alert("Wrong searching regex") end end @@ -1388,7 +1386,7 @@ codeView.eventHandler = function(workspace, object, e1, e2, e3, e4, e5) end tick(true) - elseif e1 == "key_down" then + elseif e1 == "key_down" and GUI.focusedItem == window then -- Ctrl or CMD if keyboard.isControlDown() or keyboard.isCommandDown() then -- Slash diff --git a/Libraries/GUI.lua b/Libraries/GUI.lua index d986128f..ff16b88c 100755 --- a/Libraries/GUI.lua +++ b/Libraries/GUI.lua @@ -4254,6 +4254,8 @@ end local function windowEventHandler(workspace, window, e1, e2, e3, e4, ...) if window.movingEnabled then if e1 == "touch" then + GUI.focusedItem = window + if not windowCheck(window, e3, e4) then window.lastTouchX, window.lastTouchY = e3, e4 end diff --git a/Libraries/Paths.lua b/Libraries/Paths.lua index beee98b0..94c20776 100755 --- a/Libraries/Paths.lua +++ b/Libraries/Paths.lua @@ -22,6 +22,7 @@ paths.system.applicationFinder = paths.system.applications .. "Finder.app/Main.l paths.system.applicationPictureEdit = paths.system.applications .. "Picture Edit.app/Main.lua" paths.system.applicationSettings = paths.system.applications .. "Settings.app/Main.lua" paths.system.applicationPrint3D = paths.system.applications .. "3D Print.app/Main.lua" +paths.system.applicationConsole = paths.system.applications .. "Console.app/Main.lua" -------------------------------------------------------------------------------- diff --git a/Libraries/System.lua b/Libraries/System.lua index 3b57eae5..d21264a9 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -1623,8 +1623,8 @@ end -------------------------------------------------------------------------------- local function updateMenu() - local focusedWindow = desktopWindowsContainer.children[#desktopWindowsContainer.children] - desktopMenu.children = focusedWindow and focusedWindow.menu.children or system.menuInitialChildren + local topmostWindow = desktopWindowsContainer.children[#desktopWindowsContainer.children] + desktopMenu.children = topmostWindow and topmostWindow.menu.children or system.menuInitialChildren end local function setWorkspaceHidden(state) @@ -1690,6 +1690,7 @@ function system.addWindow(window, dontAddToDock, preserveCoordinates) end -- Ебурим окно к окнам + GUI.focusedItem = window desktopWindowsContainer:addChild(window) if not dontAddToDock then @@ -2101,6 +2102,7 @@ function system.updateWallpaper() end elseif extension == ".lua" then local result, reason = loadfile(userSettings.interfaceWallpaperPath) + if result then result, functionOrReason = xpcall(result, debug.traceback) if result then @@ -2250,6 +2252,7 @@ function system.updateDesktop() icon.onLeftClick = function(icon, ...) if icon.windows then for window in pairs(icon.windows) do + GUI.focusedItem = window window.hidden = false window:moveToFront() end @@ -2587,6 +2590,7 @@ function system.updateDesktop() end system.menuInitialChildren = desktopMenu.children + system.consoleWindow = nil system.updateColorScheme() system.updateResolution() @@ -2885,6 +2889,37 @@ filesystem.write(temporaryPath, "") bootRealTime = math.floor(filesystem.lastModified(temporaryPath) / 1000) filesystem.remove(temporaryPath) +-- Meow +_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 + end + end + + local args = {...} + + for i = 1, #args do + args[i] = tostring(args[i]) + end + + args = table.concat(args, " ") + + system.consoleWindow.hidden = false + system.consoleWindow.addLine(args) + system.consoleWindow:moveToFront() +end + -------------------------------------------------------------------------------- return system