1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 17:40:26 +00:00

remove preferred apps/alternates - same can be accomplished using aliases

This commit is contained in:
kepler155c@gmail.com 2020-06-15 19:54:42 -06:00
parent 156b604a58
commit 42bd4b2b69
8 changed files with 64 additions and 151 deletions

View File

@ -1,4 +1,3 @@
local Alt = require('opus.alternate')
local Config = require('opus.config') local Config = require('opus.config')
local Event = require('opus.event') local Event = require('opus.event')
local pastebin = require('opus.http.pastebin') local pastebin = require('opus.http.pastebin')
@ -351,7 +350,7 @@ function Browser:eventHandler(event)
self:setStatus('Started cloud edit') self:setStatus('Started cloud edit')
elseif event.type == 'shell' then elseif event.type == 'shell' then
self:run(Alt.get('shell')) self:run('shell')
elseif event.type == 'refresh' then elseif event.type == 'refresh' then
self:updateDirectory(self.dir) self:updateDirectory(self.dir)

View File

@ -1,4 +1,3 @@
local Alt = require('opus.alternate')
local Array = require('opus.array') local Array = require('opus.array')
local class = require('opus.class') local class = require('opus.class')
local Config = require('opus.config') local Config = require('opus.config')
@ -469,13 +468,13 @@ function page:eventHandler(event)
shell.switchTab(shell.openTab(event.button.app.run)) shell.switchTab(shell.openTab(event.button.app.run))
elseif event.type == 'shell' then elseif event.type == 'shell' then
shell.switchTab(shell.openTab(Alt.get('shell'))) shell.switchTab(shell.openTab('shell'))
elseif event.type == 'lua' then elseif event.type == 'lua' then
shell.switchTab(shell.openTab(Alt.get('lua'))) shell.switchTab(shell.openTab('Lua'))
elseif event.type == 'files' then elseif event.type == 'files' then
shell.switchTab(shell.openTab(Alt.get('files'))) shell.switchTab(shell.openTab('Files'))
elseif event.type == 'network' then elseif event.type == 'network' then
shell.switchTab(shell.openTab('Network')) shell.switchTab(shell.openTab('Network'))

View File

@ -1,5 +1,3 @@
local Alt = require('opus.alternate')
local kernel = _G.kernel local kernel = _G.kernel
local os = _G.os local os = _G.os
local shell = _ENV.shell local shell = _ENV.shell
@ -20,7 +18,7 @@ kernel.hook('kernel_focus', function(_, eventData)
end end
end end
if nextTab == launcherTab then if nextTab == launcherTab then
shell.switchTab(shell.openTab(Alt.get('shell'))) shell.switchTab(shell.openTab('shell'))
else else
shell.switchTab(nextTab.uid) shell.switchTab(nextTab.uid)
end end

View File

@ -1,9 +1,9 @@
local Alt = require('opus.alternate')
local Event = require('opus.event') local Event = require('opus.event')
local Socket = require('opus.socket') local Socket = require('opus.socket')
local Util = require('opus.util') local Util = require('opus.util')
local kernel = _G.kernel local kernel = _G.kernel
local shell = _ENV.shell
local term = _G.term local term = _G.term
local window = _G.window local window = _G.window
@ -46,7 +46,7 @@ local function telnetHost(socket, mode)
title = mode .. ' client', title = mode .. ' client',
hidden = true, hidden = true,
fn = function() fn = function()
Util.run(kernel.makeEnv(_ENV), Alt.get('shell'), table.unpack(termInfo.program)) Util.run(kernel.makeEnv(_ENV), shell.resolveProgram('shell'), table.unpack(termInfo.program))
if socket.queue then if socket.queue then
socket:write(socket.queue) socket:write(socket.queue)
end end

View File

@ -131,7 +131,14 @@ function shell.exit()
end end
function shell.dir() return DIR end function shell.dir() return DIR end
function shell.setDir(d) DIR = d end function shell.setDir(d)
d = fs.combine(d, '')
if not fs.isDir(d) then
error("Not a directory", 2)
end
DIR = d
end
function shell.path() return PATH end function shell.path() return PATH end
function shell.setPath(p) PATH = p end function shell.setPath(p) PATH = p end
@ -155,24 +162,29 @@ function shell.resolveProgram(_sCommand)
local function inPath() local function inPath()
-- Otherwise, look on the path variable -- Otherwise, look on the path variable
if not _sCommand:find('/') then for sPath in string.gmatch(PATH or '', "[^:]+") do
for sPath in string.gmatch(PATH or '', "[^:]+") do sPath = fs.combine(sPath, _sCommand )
sPath = fs.combine(sPath, _sCommand ) if check(sPath) then
if fs.exists(sPath) and not fs.isDir(sPath) then return sPath
return sPath end
end if check(sPath .. '.lua') then
if fs.exists(sPath .. '.lua') then return sPath .. '.lua'
return sPath .. '.lua'
end
end end
end end
end end
return check(_sCommand) if not _sCommand:find('/') then
or check(_sCommand .. '.lua') return inPath()
or check(shell.resolve(_sCommand)) end
-- so... even if you are in the rom directory and you run:
-- 'packages/common/edit.lua', allow this even though it
-- does not use a leading slash. Ideally, fs.combine would
-- provide the leading slash... but it does not.
return check(shell.resolve(_sCommand))
or check(shell.resolve(_sCommand) .. '.lua') or check(shell.resolve(_sCommand) .. '.lua')
or inPath() or check(_sCommand)
or check(_sCommand .. '.lua')
end end
function shell.programs(_bIncludeHidden) function shell.programs(_bIncludeHidden)

View File

@ -1,77 +0,0 @@
local Array = require('opus.array')
local Config = require('opus.config')
local UI = require('opus.ui')
local tab = UI.Tab {
title = 'Preferred',
description = 'Select preferred applications',
apps = UI.ScrollingGrid {
x = 2, y = 2,
ex = 12, ey = -3,
columns = {
{ key = 'name' },
},
sortColumn = 'name',
disableHeader = true,
},
choices = UI.Grid {
x = 14, y = 2,
ex = -2, ey = -3,
disableHeader = true,
columns = {
{ key = 'file' },
},
getRowTextColor = function(self, row)
if row == self.values[1] then
return 'yellow'
end
return UI.Grid.getRowTextColor(self, row)
end,
},
statusBar = UI.StatusBar {
values = 'Double-click to set as preferred'
},
}
function tab:updateChoices()
local app = self.apps:getSelected().name
local choices = { }
for _, v in pairs(self.config[app]) do
table.insert(choices, { file = v })
end
self.choices:setValues(choices)
self.choices:draw()
end
function tab:enable()
self.config = Config.load('alternate')
local apps = { }
for k, _ in pairs(self.config) do
table.insert(apps, { name = k })
end
self.apps:setValues(apps)
self:updateChoices()
UI.Tab.enable(self)
end
function tab:eventHandler(event)
if event.type == 'grid_focus_row' and event.element == self.apps then
self:updateChoices()
elseif event.type == 'grid_select' and event.element == self.choices then
local app = self.apps:getSelected().name
Array.removeByValue(self.config[app], event.selected.file)
table.insert(self.config[app], 1, event.selected.file)
self:updateChoices()
Config.update('alternate', self.config)
else
return UI.Tab.eventHandler(self, event)
end
return true
end
return tab

View File

@ -1,48 +0,0 @@
local Array = require('opus.array')
local Config = require('opus.config')
local Util = require('opus.util')
local function getConfig()
return Config.load('alternate', {
shell = {
'sys/apps/shell.lua',
'rom/programs/shell.lua',
},
lua = {
'sys/apps/Lua.lua',
'rom/programs/lua.lua',
},
files = {
'sys/apps/Files.lua',
}
})
end
local Alt = { }
function Alt.get(key)
return getConfig()[key][1]
end
function Alt.set(key, value)
local config = getConfig()
Array.removeByValue(config[key], value)
table.insert(config[key], 1, value)
Config.update('alternate', config)
end
function Alt.remove(key, value)
local config = getConfig()
Array.removeByValue(config[key], value)
Config.update('alternate', config)
end
function Alt.add(key, value)
local config = getConfig()
if not Util.contains(config[key], value) then
table.insert(config[key], value)
Config.update('alternate', config)
end
end
return Alt

View File

@ -79,10 +79,40 @@ function ramfs.list(node, dir)
end end
function ramfs.open(node, fn, fl) function ramfs.open(node, fn, fl)
if fl ~= 'r' and fl ~= 'w' and fl ~= 'rb' and fl ~= 'wb' then local modes = Util.transpose { 'r', 'w', 'rb', 'wb', 'a' }
if not modes[fl] then
error('Unsupported mode') error('Unsupported mode')
end end
if fl == 'a' then
if node.mountPoint ~= fn then
fl = 'w'
else
local c = type(node.contents) == 'table'
and string.char(table.unpack(node.contents))
or node.contents
or ''
return {
write = function(str)
c = c .. str
end,
writeLine = function(str)
c = c .. str .. '\n'
end,
flush = function()
node.contents = c
node.size = #c
end,
close = function()
node.contents = c
node.size = #c
c = nil
end,
}
end
end
if fl == 'r' then if fl == 'r' then
if node.mountPoint ~= fn then if node.mountPoint ~= fn then
return return