ComputerCraft Archive

hotkeys

computer utility kepler155c github

Description

ComputerCraft OS

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/autorun/hotkeys.lua hotkeys
Archive:wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-autorun-hotkeys hotkeys
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-autorun-hotkeys hotkeys

Usage

Run: hotkeys

Tags

none

Source

View Original Source

Code Preview

local Util = require('opus.util')

local kernel     = _G.kernel
local keyboard   = _G.device.keyboard
local multishell = _ENV.multishell

if multishell and multishell.getTabs then
	-- restart tab
	keyboard.addHotkey('control-backspace', function()
		local tab = kernel.getFocused()
		if tab and not tab.noTerminate then
			multishell.terminate(tab.uid)
			multishell.openTab(tab.env, {
				path = tab.path,
				args = tab.args,
				focused = true,
			})
		end
	end)
end

-- next tab
keyboard.addHotkey('control-tab', function()
	local visibleTabs = { }
	local currentTab = kernel.getFocused()

	local function compareTab(a, b)
		return a.uid < b.uid
	end
	for _,tab in Util.spairs(kernel.routines, compareTab) do
		if not tab.hidden and not tab.noFocus then
			table.insert(visibleTabs, tab)
		end
	end

	for k,tab in ipairs(visibleTabs) do
		if tab.uid == currentTab.uid then
			if k < #visibleTabs then
				kernel.raise(visibleTabs[k + 1].uid)
				return
			end
		end
	end
	if #visibleTabs > 0 then
		kernel.raise(visibleTabs[1].uid)
	end
end)