diff --git a/common/debugMonitor.lua b/common/debugMonitor.lua index 74e8c84..d198f77 100644 --- a/common/debugMonitor.lua +++ b/common/debugMonitor.lua @@ -6,12 +6,16 @@ local peripheral = _G.peripheral local term = _G.term local args = { ... } -local mon = args[1] and device[args[1]] or peripheral.wrap(args[1]) or +local mon = not args[1] and term.current() or + device[args[1]] or + peripheral.wrap(args[1]) or peripheral.find('monitor') or error('Syntax: debug ') mon.clear() -mon.setTextScale(.5) +if mon.setTextScale then + mon.setTextScale(.5) +end mon.setCursorPos(1, 1) local oldDebug = _G._syslog @@ -26,7 +30,9 @@ repeat local e, side = os.pullEventRaw('monitor_touch') if e == 'monitor_touch' and side == mon.side then mon.clear() - mon.setTextScale(.5) + if mon.setTextScale then + mon.setTextScale(.5) + end mon.setCursorPos(1, 1) end until e == 'terminate' diff --git a/common/edit.lua b/common/edit.lua index f0c7be3..27784e1 100644 --- a/common/edit.lua +++ b/common/edit.lua @@ -202,7 +202,6 @@ local page = UI.Page { label = 'Find', search = UI.TextEntry { x = 7, ex = -3, - limit = 512, accelerators = { [ 'enter' ] = 'accept', }, @@ -232,7 +231,6 @@ local page = UI.Page { label = 'Save', filename = UI.TextEntry { x = 7, ex = -3, - limit = 512, accelerators = { [ 'enter' ] = 'accept', }, @@ -339,7 +337,6 @@ local page = UI.Page { quick_open = UI.SlideOut { filter_entry = UI.TextEntry { x = 2, y = 2, ex = -2, - limit = 256, shadowText = 'File name', accelerators = { [ 'enter' ] = 'accept', diff --git a/lzwfs/system/lzwfs.lua b/lzwfs/system/lzwfs.lua index 69bccee..5f898bd 100644 --- a/lzwfs/system/lzwfs.lua +++ b/lzwfs/system/lzwfs.lua @@ -29,7 +29,6 @@ local tab = UI.Tab { }, entry = UI.TextEntry { x = 3, y = 5 , ex = -3, - limit = 256, shadowText = 'enter new path', accelerators = { enter = 'add_path', diff --git a/neural/apis/glasses.lua b/neural/apis/glasses.lua index 1d8a1d4..1224883 100644 --- a/neural/apis/glasses.lua +++ b/neural/apis/glasses.lua @@ -5,7 +5,6 @@ local Terminal = require('opus.terminal') local Util = require('opus.util') -local colors = _G.colors local device = _G.device local Glasses = { } @@ -102,6 +101,13 @@ function Glasses.create(args) function gterm.getTextScale() return opts.scale end + function gterm.move(x, y) + if opts.x ~= x or opts.y ~= y then + opts.x, opts.y = x, y + pos = { x = opts.x * xs, y = opts.y * ys } + group.setPosition(pos.x, pos.y) + end + end gterm.name = opts.name gterm.side = opts.name diff --git a/neural/fisher.lua b/neural/fisher.lua index 88597af..d9c4c8a 100644 --- a/neural/fisher.lua +++ b/neural/fisher.lua @@ -47,7 +47,7 @@ local fsm = machine.create({ -- state changes onenterwait = function() - print('waitng for fishing rod to be selected') + print('waiting for fishing rod to be selected') if icon then icon.remove() icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' ) diff --git a/neural/nwm.lua b/neural/nwm.lua index 7e54db0..91d2fe5 100644 --- a/neural/nwm.lua +++ b/neural/nwm.lua @@ -1,6 +1,9 @@ --[[ A simplistic window manager for glasses. - TODO: support moving windows via mouse drag. + + TODO: + opacity for text/background separately + support for specifying scale factor ]] local Config = require('opus.config') @@ -8,15 +11,17 @@ local Glasses = require('neural.glasses') local UI = require('opus.ui') local Util = require('opus.util') +local fs = _G.fs local kernel = _G.kernel local multishell = _ENV.multishell local shell = _ENV.shell local config = Config.load('nwm', { session = { } }) --- TODO: figure out how to better define scaling +-- TODO: figure out how to better support scaling local scale = .5 local xs, ys = 6 * scale, 9 * scale +local dragging local events = { glasses_click = 'mouse_click', @@ -31,16 +36,39 @@ local function hook(e, eventData) local y = math.floor(eventData[3] / ys) local clickedTab + if dragging then + if e == 'glasses_up' then + dragging = nil + elseif e == 'glasses_drag' then + local dx = x - dragging.ax + local dy = y - dragging.ay + dragging.tab.window.move(dragging.wx + dx, dragging.wy + dy) + dragging.tab.titleBar.move(dragging.wx + dx, dragging.wy + dy - 1) + + dragging.tab.wmargs.x = dragging.wx + dx + dragging.tab.wmargs.y = dragging.wy + dy + Config.update('nwm', config) + end + return + end + for _,tab in ipairs(kernel.routines) do if tab.window.type == 'glasses' then local wx, wy = tab.window.getPosition() local ww, wh = tab.window.getSize() - if x >= wx and x <= wx + ww and y >= wy and y <= wy + wh then + if x >= wx and x <= wx + ww and y > wy and y < wy + wh then clickedTab = tab x = x - wx y = y - wy break + elseif e == 'glasses_click' and x >= wx and x <= wx + ww and y == wy then + if x == wx + ww - 1 then + multishell.terminate(tab.uid) + else + dragging = { tab = tab, ax = x, ay = y, wx = wx, wy = wy } + end + return end end end @@ -65,6 +93,18 @@ kernel.hook(hookEvents, hook) local function run(args) local window = Glasses.create(args) + local titleBar = Glasses.create({ + x = args.x, + y = args.y - 1, + height = 1, + width = args.width, + opacity = args.opacity, + }) + titleBar.canvas:clear('yellow') + titleBar.canvas:write(1, 1, ' ' .. fs.getName(args.path), nil, 'black') + titleBar.canvas:write(args.width - 2, 1, ' x ', nil, 'black') + titleBar.redraw() + multishell.openTab({ path = args.path, args = args.args, @@ -73,8 +113,11 @@ local function run(args) Util.removeByValue(config.session, args) Config.update('nwm', config) window.destroy() + titleBar.destroy() end, window = window, + titleBar = titleBar, + wmargs = args, }) end @@ -90,6 +133,8 @@ UI:setPage(UI.Page { UI.Slider { min = 0, max = 255, formLabel = 'Opacity', formKey = 'opacity', formIndex = 3, + labelWidth = 3, + transform = math.floor, }, UI.Text { x = 10, y = 5, @@ -137,6 +182,9 @@ UI:setPage(UI.Page { run(opts) self.notification:success('Started program') end + + elseif event.type == 'form_cancel' then + UI:quit() end return UI.Page.eventHandler(self, event) end,