local sys = require 'lx.sys' local sysdef= require 'lx.sysdef' local ioctl = require 'lx.ioctl' local draw = require 'lx.draw' local gui = require 'lx.gui' local mainloop = require 'lx.mainloop' local tk = require 'lx.tk' print("Hello, world!") gui.open() gui.load_cursor('sys:/cursors/left_ptr.png') gui.show_cursor() for x = 0, 255, 16 do for y = 0, 255, 16 do gui.surface:fillrect(x, y, 16, 16, gui.surface:rgb(x, y, 0)) end end local f = draw.load_image('root:/logo.png') local wm = tk.window_manager() tk.init(gui, wm) local img = tk.image(f) wm:add({title = "Window 1", x = 100, y = 16}, img) local img2 = tk.box({ center_content = true, vscroll = true, hscroll = true, vresize = true, hresize = true, }, tk.image(f)) wm:add({title = "Window 2", x = 16, y = 100}, img2) local img3 = tk.box({ constrain_size = true, vresize = true, hresize = true, }, tk.image(f)) wm:add({title = "Window 3", x = 300, y = 150}, img3) local txt = tk.text({color = tk.rgb(0, 255, 0), width=200}, "Hello, world!\nThis is a long text") wm:add({title = "Text example", x = 32, y = 32}, txt) function alert(text, on_dismiss) local win = {} win.widget = tk.grid({}, { { tk.text({padding = 16}, text) }, { tk.box({center_content = true, height = 40}, tk.text({background = tk.theme.colors.button.good.bg(tk), color = tk.theme.colors.button.good.text(tk), padding = 4, on_click = function() win.close() end}, "Ok")) } }) win.close = function() sys.dbg_print("Hello!") wm:remove(win.win) if on_dismiss then on_dismiss() end end win.win = wm:add({title = "Alert", x = math.random(0, gui.surface:width() - 100), y = math.random(0, gui.surface:height() - 100), }, win.widget) end function loopy() alert("Hello, world !!", loopy) gui.hide_cursor() gui.surface:fillrect(0, 0, gui.surface:width(), gui.surface:height(), gui.surface:rgb(0, 0, 0)) gui.show_cursor() wm:redraw(0, 0, gui.surface:width(), gui.surface:height()) end loopy() -- A small file manager test :) local function open_listing(path) local function fileline(name, path, size) return { tk.text(name), tk.text(tostring(size)), tk.box({center_content = true, width = 32}, tk.text({background = tk.theme.colors.button.action.bg(tk), color = tk.theme.colors.button.action.text(tk), on_click = function() open_listing(path) end}, "open")) } end local griditems = { { tk.box({hresize = true, width = 200, constrain_size = true, min_width = 16, control_size = 8}, tk.text("Name")), tk.box({hresize = true, width = 75, constrain_size = true, min_width = 16, control_size = 8}, tk.text("Size")), tk.box({constrain_size = true}, tk.text("Actions")) } } local fd = sys.open(path, sysdef.FM_READDIR) if not fd then alert("Could not FM_READDIR " .. path) return end local i = 0 while true do x = sys.readdir(fd, i) if not x then break end table.insert(griditems, fileline(x.name .. (x.type & sysdef.FT_DIR ~= 0 and "/" or ""), path .. x.name .. "/", x.size)) i = i + 1 end sys.close(fd) local grid = tk.grid({border_size = 1}, griditems) wm:add({title = path, x = math.random(0, gui.surface:width() - 100), y = math.random(0, gui.surface:height() - 100)}, tk.box({vresize = true, hresize = true, vscroll = true, hscroll = true}, grid)) end local function fsline(fs) return { tk.text(fs .. ":/"), tk.box({center_content = true, width = 32}, tk.text({background = tk.theme.colors.button.action.bg(tk), color = tk.theme.colors.button.action.text(tk), on_click = function() open_listing(fs .. ":/") end}, "open")) } end local grid = tk.grid({border_size = 1}, { { tk.box({hresize = true, width = 200, constrain_size = true, min_width = 16, control_size = 8}, tk.text("Name")), tk.box({constrain_size = true}, tk.text("Actions")) }, fsline("io"), fsline("root"), fsline("config"), fsline("app"), fsline("sys"), }) wm:add({title = "Filesystems", x = 300, y = 20}, tk.box({vresize = true, hresize = true, vscroll = true, hscroll = true}, grid)) function open_terminal(title, binfile) local term_widget = tk.gipwidget({width = 480, height = 360}) wm:add({title = title, x = 300, y = 200}, term_widget) local tty_a, tty_b = sys.make_channel(false) local term_bin_pid = sys.new_proc() sys.bind_fs(term_bin_pid, "sys", "sys") sys.bind_fs(term_bin_pid, "config", "config") sys.bind_fd(term_bin_pid, sysdef.STD_FD_GIP, term_widget.ch_cli) sys.bind_fd(term_bin_pid, sysdef.STD_FD_TTYSRV, tty_a) sys.dbg_print("Start terminal.bin, pid: " .. tonumber(term_bin_pid)) sys.proc_exec(term_bin_pid, "sys:/bin/terminal.bin") local shell_bin_pid = sys.new_proc() sys.bind_fs(shell_bin_pid, "root", "root") sys.bind_fs(shell_bin_pid, "sys", "sys") sys.bind_fs(shell_bin_pid, "config", "config") sys.bind_fd(shell_bin_pid, sysdef.STD_FD_TTY_STDIO, tty_b) sys.dbg_print("Start " .. binfile .. ", pid: " .. tonumber(shell_bin_pid)) sys.proc_exec(shell_bin_pid, binfile) end open_terminal("Shell", "sys:/bin/shell.bin") open_terminal("Lua prompt", "sys:/bin/lx.bin") mainloop.run() os.exit()