mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-20 02:59:20 +01:00
Added Lua interpreter application
This commit is contained in:
parent
e15741c24a
commit
fee7ca24de
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
.DS_Store
|
||||
Mounts/
|
||||
Temporary/
|
||||
Users/
|
||||
Users/
|
||||
|
||||
@ -283,7 +283,7 @@ updateSidebar = function()
|
||||
for proxy, path in filesystem.mounts() do
|
||||
if not proxy.networkModem and not proxy.networkFTP then
|
||||
if proxy ~= filesystem.getProxy() then
|
||||
addSidebarItem(" " .. (proxy.getLabel() or filesystem.name(path)), path).onTouch = function()
|
||||
addSidebarItem(" " .. (proxy.getLabel() or proxy.address), path).onTouch = function()
|
||||
onFavouriteTouch(path)
|
||||
end
|
||||
end
|
||||
|
||||
Binary file not shown.
@ -1,40 +1,210 @@
|
||||
|
||||
local GUI = require("GUI")
|
||||
local system = require("System")
|
||||
local screen = require("Screen")
|
||||
local text = require("Text")
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
local workspace, window, menu = system.addWindow(GUI.titledWindow(1, 1, 90, 25, "Terminal", true))
|
||||
local HISTORY_LIMIT = 100
|
||||
|
||||
local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 90, 25, 0xE1E1E1))
|
||||
local localization = system.getCurrentScriptLocalization()
|
||||
|
||||
local lines = {
|
||||
{
|
||||
text = (computer.getArchitecture and computer.getArchitecture() or "Lua 5.2") .. " Copyright (C) 1994-2019 Lua.org, PUC-Rio",
|
||||
color = 0x969696,
|
||||
}
|
||||
{ text = (computer.getArchitecture and computer.getArchitecture() or "Lua 5.2") .. " Copyright (C) 1994-2019 Lua.org, PUC-Rio", color = 0x696969 },
|
||||
{ text = "Type a statement and hit Enter to evaluate it", color = 0x969696 },
|
||||
{ text = "Prefix an expression with \"=\" to show its value", color = 0x969696 },
|
||||
"\t",
|
||||
}
|
||||
|
||||
local textBox = window:addChild(GUI.textBox(2, 2, 1, 1, nil, 0x3C3C3C, lines, 1, 0, 0))
|
||||
local treePanel = window:addChild(GUI.panel(1, 1, 22, 3, 0x2D2D2D))
|
||||
local tree = window:addChild(GUI.tree(1, 4, treePanel.width, 1, 0x2D2D2D, 0xE1E1E1, 0x969696, 0x696969, 0xE1E1E1, 0x2D2D2D, 0x696969, 0x696969, 0x4B4B4B, 0x696969, GUI.IO_MODE_BOTH, GUI.IO_MODE_BOTH))
|
||||
|
||||
local textBox = window:addChild(GUI.textBox(1, 2, 1, 1, nil, 0x3C3C3C, lines, 1, 0, 0, true))
|
||||
textBox.passScreenEvents = true
|
||||
|
||||
local input = window:addChild(GUI.input(1, 1, 1, 3, 0xE1E1E1, 0x2D2D2D, 0x969696, 0xE1E1E1, 0x2D2D2D, "", "Type statement here"))
|
||||
local input = window:addChild(GUI.input(1, 1, 1, 3, 0xD2D2D2, 0x3C3C3C, 0x969696, 0xD2D2D2, 0x3C3C3C, "", "Type statement here"))
|
||||
local lastInput = input.text
|
||||
input.historyEnabled = true
|
||||
input.onInputFinished = function()
|
||||
|
||||
|
||||
input.text = ""
|
||||
-- input.textDrawMethod = function(x, y, color, text)
|
||||
-- if text == input.placeholderText then
|
||||
-- screen.drawText(x, y, color, text)
|
||||
-- else
|
||||
-- GUI.highlightString(x, y, input.width - 2, 1, 2, GUI.LUA_SYNTAX_PATTERNS, GUI.LUA_SYNTAX_COLOR_SCHEME, text)
|
||||
-- end
|
||||
-- end
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
local function add(color, text)
|
||||
if color then
|
||||
table.insert(lines, {
|
||||
text = text,
|
||||
color = color,
|
||||
})
|
||||
else
|
||||
table.insert(lines, text)
|
||||
end
|
||||
|
||||
if #lines > HISTORY_LIMIT then
|
||||
table.remove(lines, 1)
|
||||
end
|
||||
end
|
||||
|
||||
local function addMultiple(color, ...)
|
||||
local args = {...}
|
||||
for i = 1, #args do
|
||||
if type(args[i]) == "table" then
|
||||
args[i] = text.serialize(args[i], true, " ", 3)
|
||||
else
|
||||
args[i] = tostring(args[i])
|
||||
end
|
||||
end
|
||||
|
||||
for part in table.concat(args, ", "):gmatch("[^\r\n]+") do
|
||||
add(color, part)
|
||||
end
|
||||
|
||||
textBox:scrollToEnd()
|
||||
end
|
||||
|
||||
local function addPrint(...)
|
||||
addMultiple(nil, ...)
|
||||
end
|
||||
|
||||
local function addError(...)
|
||||
addMultiple(0x880000, ...)
|
||||
end
|
||||
|
||||
local sandbox = {}
|
||||
|
||||
for key, value in pairs(_G) do
|
||||
sandbox[key] = value
|
||||
end
|
||||
|
||||
sandbox.print = function(...)
|
||||
addPrint(...)
|
||||
workspace:draw()
|
||||
end
|
||||
|
||||
local function updateTree()
|
||||
local function updateRecursively(t, definitionName, offset)
|
||||
local list = {}
|
||||
for key in pairs(t) do
|
||||
table.insert(list, key)
|
||||
end
|
||||
|
||||
local i, expandables = 1, {}
|
||||
while i <= #list do
|
||||
if type(t[list[i]]) == "table" then
|
||||
table.insert(expandables, list[i])
|
||||
table.remove(list, i)
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(expandables, function(a, b) return unicode.lower(tostring(a)) < unicode.lower(tostring(b)) end)
|
||||
table.sort(list, function(a, b) return unicode.lower(tostring(a)) < unicode.lower(tostring(b)) end)
|
||||
|
||||
for i = 1, #expandables do
|
||||
local definition = definitionName .. expandables[i] .. "."
|
||||
|
||||
tree:addItem(
|
||||
tostring(expandables[i]),
|
||||
definition,
|
||||
offset,
|
||||
true
|
||||
)
|
||||
|
||||
if tree.expandedItems[definition] then
|
||||
updateRecursively(t[expandables[i]], definition, offset + 2)
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #list do
|
||||
tree:addItem(
|
||||
tostring(list[i]),
|
||||
definitionName .. list[i] .. "()",
|
||||
offset,
|
||||
false
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
tree.items = {}
|
||||
updateRecursively(sandbox, "", 1)
|
||||
end
|
||||
|
||||
tree.onItemExpanded = function()
|
||||
updateTree()
|
||||
end
|
||||
|
||||
tree.onItemSelected = function()
|
||||
input.text = lastInput .. tree.selectedItem
|
||||
workspace:draw()
|
||||
end
|
||||
|
||||
input.onKeyDown = function(workspace, input, e1, e2, e3, e4)
|
||||
if e4 == 28 then
|
||||
local text = input.text:match("^[%s%t]+(.)") or input.text
|
||||
input.text = ""
|
||||
lastInput = ""
|
||||
|
||||
add(0x969696, "> " .. text)
|
||||
|
||||
local pizda = text:match("^=+(.+)")
|
||||
if pizda then
|
||||
text = "return " .. pizda
|
||||
end
|
||||
|
||||
local result, reason = load(text, "=lua", "t", sandbox)
|
||||
if result then
|
||||
result = {xpcall(result, debug.traceback)}
|
||||
|
||||
if result[1] then
|
||||
if #result > 1 then
|
||||
addPrint(table.unpack(result, 2))
|
||||
end
|
||||
else
|
||||
addError(table.unpack(result, 2))
|
||||
end
|
||||
else
|
||||
addError(reason)
|
||||
end
|
||||
|
||||
workspace:draw()
|
||||
else
|
||||
lastInput = input.text
|
||||
end
|
||||
end
|
||||
|
||||
input.onInputFinished = function()
|
||||
|
||||
end
|
||||
|
||||
window.onResize = function(width, height)
|
||||
window.backgroundPanel.width, window.backgroundPanel.height = width, height
|
||||
textBox.width, textBox.height = width - 2, height - 4
|
||||
input.localY, input.width = height - input.height + 1, width
|
||||
window.backgroundPanel.localX = tree.width + 1
|
||||
window.backgroundPanel.width = width - tree.width
|
||||
window.backgroundPanel.height = height - 3
|
||||
|
||||
textBox.localX = window.backgroundPanel.localX + 1
|
||||
textBox.width = window.backgroundPanel.width - 2
|
||||
textBox.height = window.backgroundPanel.height - 2
|
||||
|
||||
tree.height = height - 3
|
||||
|
||||
input.localX = window.backgroundPanel.localX
|
||||
input.localY = height - input.height + 1
|
||||
input.width = window.backgroundPanel.width
|
||||
end
|
||||
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
updateTree()
|
||||
window.actionButtons:moveToFront()
|
||||
window:resize(window.width, window.height)
|
||||
workspace:draw()
|
||||
|
||||
@ -13,3 +13,15 @@ end
|
||||
function component.isAvailable(type)
|
||||
return component.list(type)() and true or false
|
||||
end
|
||||
|
||||
-- Allows writing component.gpu.set(...) instead of component.get("gpu").set(...)
|
||||
setmetatable(component, {
|
||||
__index = function(_, key)
|
||||
local proxy, reason = component.get(key)
|
||||
if proxy then
|
||||
return proxy
|
||||
else
|
||||
error(reason)
|
||||
end
|
||||
end,
|
||||
})
|
||||
@ -58,8 +58,6 @@ local GUI = {
|
||||
WINDOW_TAB_BAR_SELECTED_BACKGROUND_COLOR = 0xF0F0F0,
|
||||
WINDOW_TAB_BAR_SELECTED_TEXT_COLOR = 0x2D2D2D,
|
||||
|
||||
PALETTE_CONFIG_PATH = paths.system.libraries .. ".palette.cfg",
|
||||
|
||||
LUA_SYNTAX_COLOR_SCHEME = {
|
||||
background = 0x1E1E1E,
|
||||
text = 0xE1E1E1,
|
||||
@ -2798,7 +2796,7 @@ local function inputStartInput(input)
|
||||
input.text = ""
|
||||
end
|
||||
|
||||
input:setCursorPosition(unicode.len(input.text) + 1)
|
||||
input:setCursorPosition(input.cursorPosition)
|
||||
|
||||
input.stopInputObject.width, input.stopInputObject.height = input.firstParent.width, input.firstParent.height
|
||||
input.firstParent:addChild(input.stopInputObject)
|
||||
@ -2806,10 +2804,11 @@ local function inputStartInput(input)
|
||||
inputCursorBlink(input.firstParent, input, true)
|
||||
end
|
||||
|
||||
local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6)
|
||||
local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6, ...)
|
||||
if e1 == "touch" or e1 == "drag" then
|
||||
input:setCursorPosition(input.textCutFrom + e3 - input.x - input.textOffset)
|
||||
|
||||
if input.focused then
|
||||
input:setCursorPosition(input.textCutFrom + e3 - input.x - input.textOffset)
|
||||
inputCursorBlink(workspace, input, true)
|
||||
else
|
||||
input:startInput()
|
||||
@ -2833,6 +2832,11 @@ local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6)
|
||||
end
|
||||
|
||||
inputStopInput(workspace, input)
|
||||
|
||||
if input.onKeyDown then
|
||||
input.onKeyDown(workspace, input, e1, e2, e3, e4, e5, e6, ...)
|
||||
end
|
||||
|
||||
return
|
||||
-- Arrows up/down/left/right
|
||||
elseif e4 == 200 then
|
||||
@ -2883,6 +2887,10 @@ local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6)
|
||||
end
|
||||
end
|
||||
|
||||
if input.onKeyDown then
|
||||
input.onKeyDown(workspace, input, e1, e2, e3, e4, e5, e6, ...)
|
||||
end
|
||||
|
||||
inputCursorBlink(workspace, input, true)
|
||||
elseif e1 == "clipboard" and input.focused then
|
||||
input.text = unicode.sub(input.text, 1, input.cursorPosition - 1) .. e3 .. unicode.sub(input.text, input.cursorPosition, -1)
|
||||
@ -3373,13 +3381,15 @@ function GUI.palette(x, y, startColor)
|
||||
y = y + 2
|
||||
end
|
||||
|
||||
local paletteConfigPath = paths.user.applicationData .. "GUI/Palette.cfg"
|
||||
|
||||
local favourites
|
||||
if filesystem.exists(GUI.PALETTE_CONFIG_PATH) then
|
||||
favourites = filesystem.readTable(GUI.PALETTE_CONFIG_PATH)
|
||||
if filesystem.exists(paletteConfigPath) then
|
||||
favourites = filesystem.readTable(paletteConfigPath)
|
||||
else
|
||||
favourites = {}
|
||||
for i = 1, 6 do favourites[i] = color.HSBToInteger(math.random(0, 360), 1, 1) end
|
||||
filesystem.writeTable(GUI.PALETTE_CONFIG_PATH, favourites)
|
||||
filesystem.writeTable(paletteConfigPath, favourites)
|
||||
end
|
||||
|
||||
local favouritesContainer = palette:addChild(GUI.container(58, 24, 12, 1))
|
||||
@ -3409,7 +3419,7 @@ function GUI.palette(x, y, startColor)
|
||||
favouritesContainer.children[i].colors.pressed.background = 0x0
|
||||
end
|
||||
|
||||
filesystem.writeTable(GUI.PALETTE_CONFIG_PATH, favourites)
|
||||
filesystem.writeTable(paletteConfigPath, favourites)
|
||||
|
||||
workspace:draw()
|
||||
end
|
||||
|
||||
@ -20,7 +20,6 @@ paths.system.applicationMineCodeIDE = paths.system.applications .. "MineCode IDE
|
||||
paths.system.applicationFinder = paths.system.applications .. "Finder.app/Main.lua"
|
||||
paths.system.applicationPictureEdit = paths.system.applications .. "Picture Edit.app/Main.lua"
|
||||
paths.system.applicationSettings = paths.system.applications .. "Settings.app/Main.lua"
|
||||
paths.system.applicationTerminal = paths.system.applications .. "Terminal.app/Main.lua"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -3,15 +3,16 @@ local text = {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
function text.serialize(t, prettyLook, indentationWidth, indentUsingTabs, recursionStackLimit)
|
||||
function text.serialize(t, prettyLook, indentator, recursionStackLimit)
|
||||
checkArg(1, t, "table")
|
||||
|
||||
recursionStackLimit = recursionStackLimit or math.huge
|
||||
local indentationSymbolAdder = string.rep(indentUsingTabs and " " or " ", indentationWidth or 2)
|
||||
indentator = indentator or " "
|
||||
|
||||
local equalsSymbol = prettyLook and " = " or "="
|
||||
|
||||
local function serialize(t, currentIndentationSymbol, currentRecusrionStack)
|
||||
local result, nextIndentationSymbol, keyType, valueType, stringValue = {"{"}, currentIndentationSymbol .. indentationSymbolAdder
|
||||
local result, nextIndentationSymbol, keyType, valueType, stringValue = {"{"}, currentIndentationSymbol .. indentator
|
||||
|
||||
if prettyLook then
|
||||
table.insert(result, "\n")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user