mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-01-08 20:22:38 +01:00
Added global print() function & simple console application for output
This commit is contained in:
parent
fe43dacde5
commit
e7723e504a
BIN
Applications/Console.app/Icon.pic
Normal file
BIN
Applications/Console.app/Icon.pic
Normal file
Binary file not shown.
3
Applications/Console.app/Localizations/English.lang
Normal file
3
Applications/Console.app/Localizations/English.lang
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
greeting = "Hello, "
|
||||
}
|
||||
87
Applications/Console.app/Main.lua
Normal file
87
Applications/Console.app/Main.lua
Normal file
@ -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()
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user