Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tab Manager Program
- local function listTabs()
- local currentTab = multishell.getCurrent()
- local tabs = {}
- for i = 1, multishell.getCount() do
- local title = multishell.getTitle(i)
- table.insert(tabs, {id = i, title = title})
- end
- return currentTab, tabs
- end
- local function drawTabs(currentTab, tabs)
- term.clear()
- term.setCursorPos(1, 1)
- print("Tab Manager - Select a tab to switch to it")
- print("========================================")
- for _, tab in ipairs(tabs) do
- if tab.id == currentTab then
- print("-> [" .. tab.id .. "] " .. tab.title .. " (current)")
- else
- print(" [" .. tab.id .. "] " .. tab.title)
- end
- end
- end
- local function getUserSelection(tabs)
- print("\nEnter the tab number to switch to it (or 'q' to quit): ")
- local input = read()
- if input == 'q' or input == 'Q' then
- return nil
- end
- local tabNumber = tonumber(input)
- for _, tab in ipairs(tabs) do
- if tab.id == tabNumber then
- return tabNumber
- end
- end
- return nil
- end
- local function main()
- while true do
- local currentTab, tabs = listTabs()
- drawTabs(currentTab, tabs)
- local selection = getUserSelection(tabs)
- if selection then
- multishell.setFocus(selection)
- else
- break
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement