mirror of
				https://github.com/kepler155c/opus
				synced 2025-10-31 07:33:00 +00:00 
			
		
		
		
	alternatives
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | 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') | ||||||
| @@ -353,7 +354,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('sys/apps/shell.lua') | 		self:run(Alt.get('shell')) | ||||||
|  |  | ||||||
| 	elseif event.type == 'refresh' then | 	elseif event.type == 'refresh' then | ||||||
| 		self:updateDirectory(self.dir) | 		self:updateDirectory(self.dir) | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
|  | local Alt      = require('opus.alternate') | ||||||
| local class    = require('opus.class') | local class    = require('opus.class') | ||||||
| local Config   = require('opus.config') | local Config   = require('opus.config') | ||||||
| local Event    = require('opus.event') | local Event    = require('opus.event') | ||||||
| @@ -420,13 +421,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('sys/apps/shell.lua')) | 		shell.switchTab(shell.openTab(Alt.get('shell'))) | ||||||
|  |  | ||||||
| 	elseif event.type == 'lua' then | 	elseif event.type == 'lua' then | ||||||
| 		shell.switchTab(shell.openTab('sys/apps/Lua.lua')) | 		shell.switchTab(shell.openTab(Alt.get('lua'))) | ||||||
|  |  | ||||||
| 	elseif event.type == 'files' then | 	elseif event.type == 'files' then | ||||||
| 		shell.switchTab(shell.openTab('sys/apps/Files.lua')) | 		shell.switchTab(shell.openTab(Alt.get('files'))) | ||||||
|  |  | ||||||
| 	elseif event.type == 'focus_change' then | 	elseif event.type == 'focus_change' then | ||||||
| 		if event.focused.parent.UIElement == 'Icon' then | 		if event.focused.parent.UIElement == 'Icon' then | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
|  | 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') | ||||||
| @@ -46,7 +47,7 @@ local function telnetHost(socket, mode) | |||||||
| 		title = mode .. ' client', | 		title = mode .. ' client', | ||||||
| 		hidden = true, | 		hidden = true, | ||||||
| 		co = coroutine.create(function() | 		co = coroutine.create(function() | ||||||
| 			Util.run(_ENV, 'sys/apps/shell.lua', table.unpack(termInfo.program)) | 			Util.run(_ENV, Alt.get('shell'), table.unpack(termInfo.program)) | ||||||
| 			if socket.queue then | 			if socket.queue then | ||||||
| 				socket:write(socket.queue) | 				socket:write(socket.queue) | ||||||
| 			end | 			end | ||||||
|   | |||||||
							
								
								
									
										52
									
								
								sys/modules/opus/alternate.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								sys/modules/opus/alternate.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | |||||||
|  | local Config = require('opus.config') | ||||||
|  | local Util   = require('opus.util') | ||||||
|  |  | ||||||
|  | local function getConfig() | ||||||
|  |     return Config.load('alternate', { | ||||||
|  |         default = { | ||||||
|  |             shell = 'sys/apps/shell.lua', | ||||||
|  |             lua = 'sys/apps/Lua.lua', | ||||||
|  |             files = 'sys/apps/Files.lua', | ||||||
|  |         }, | ||||||
|  |         choices = { | ||||||
|  |             shell = { | ||||||
|  |                 'sys/apps/shell.lua', | ||||||
|  |                 'rom/programs/shell', | ||||||
|  |             }, | ||||||
|  |             lua = { | ||||||
|  |                 'sys/apps/Lua.lua', | ||||||
|  |                 'rom/programs/lua.lua', | ||||||
|  |             }, | ||||||
|  |             files = { | ||||||
|  |                 'sys/apps/Files.lua', | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     }) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | local Alt = { } | ||||||
|  |  | ||||||
|  | function Alt.get(key) | ||||||
|  |     return getConfig().default[key] | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function Alt.set(key, value) | ||||||
|  |     local config = getConfig() | ||||||
|  |  | ||||||
|  |     config.default[key] = value | ||||||
|  |     Config.update('alternate', config) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function Alt.addChoice(key, value) | ||||||
|  |     local config = getConfig() | ||||||
|  |  | ||||||
|  |     if not config.choices[key] then | ||||||
|  |         config.choices[key] = { } | ||||||
|  |     end | ||||||
|  |     if not Util.contains(config.choices[key], value) then | ||||||
|  |         config.choices[key] = value | ||||||
|  |         Config.update('alternate', config) | ||||||
|  |     end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | return Alt | ||||||
| @@ -621,17 +621,17 @@ end | |||||||
|  |  | ||||||
| -- http://snippets.luacode.org/?p=snippets/trim_whitespace_from_string_76 | -- http://snippets.luacode.org/?p=snippets/trim_whitespace_from_string_76 | ||||||
| function Util.trim(s) | function Util.trim(s) | ||||||
| 	return s:find'^%s*$' and '' or s:match'^%s*(.*%S)' | 	return s:find('^%s*$') and '' or s:match('^%s*(.*%S)') | ||||||
| end | end | ||||||
|  |  | ||||||
| -- trim whitespace from left end of string | -- trim whitespace from left end of string | ||||||
| function Util.triml(s) | function Util.triml(s) | ||||||
| 	return s:match'^%s*(.*)' | 	return s:match('^%s*(.*)') | ||||||
| end | end | ||||||
|  |  | ||||||
| -- trim whitespace from right end of string | -- trim whitespace from right end of string | ||||||
| function Util.trimr(s) | function Util.trimr(s) | ||||||
| 	return s:find'^%s*$' and '' or s:match'^(.*%S)' | 	return s:find('^%s*$') and '' or s:match('^(.*%S)') | ||||||
| end | end | ||||||
| -- end http://snippets.luacode.org/?p=snippets/trim_whitespace_from_string_76 | -- end http://snippets.luacode.org/?p=snippets/trim_whitespace_from_string_76 | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 kepler155c@gmail.com
					kepler155c@gmail.com