Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
// we want ctrl+R; but if we're in a browser and on linux or
// windows, then ctrl+R will result in a browser reload :(
//
// Note: even if not in a browser (i.e. running in electron mode),
// on linux and windows we have to be careful not to use the
// default reload keyboard shortcut; see app/src/main/menu.js
//
// re: RUNNING_SHELL_TEST; there seems to be some weird bug here; on linux, the ctrlKey modifier becomes sticky
if (!document.activeElement.classList.contains('repl-input-element')) {
// if we aren't focused on a repl input, don't bother
} else if (
evt.ctrlKey &&
(process.platform === 'darwin' ||
/Macintosh/.test(navigator.userAgent) ||
(!inBrowser() && !process.env.RUNNING_SHELL_TEST) ||
evt.metaKey)
) {
const tab = getTabFromTarget(evt.srcElement)
const activeSearch: ActiveISearch = tab['_kui_active_i_search']
if (evt.keyCode === KeyCodes.R) {
debug('got ctrl+r')
if (activeSearch) {
debug('continuation of existing reverse-i-search')
activeSearch.doSearch(evt as KeyboardEventPlusPlus)
} else {
debug('new reverse-i-search')
tab['_kui_active_i_search'] = new ActiveISearch(tab)
}
} else if (activeSearch && isCursorMovement(evt)) {
activeSearch.completeSearch()
// this will be our return value
const topLevelUsage = {
title: strings('helpUsageTitle'),
header: 'A summary of the top-level command structure.',
available: [],
nRowsInViewport: 8 // show a few more rows for top-level help
}
// traverse the top-level usage documents, populating topLevelUsage.available
for (const key in usage) {
const { route, usage: model } = usage[key]
if (
model &&
!model.synonymFor &&
(isHeadless() || !model.headlessOnly) &&
(!inBrowser() || !model.requiresLocal)
) {
topLevelUsage.available.push({
label: route.substring(1),
available: model.available,
hidden: model.hidden,
synonyms: model.synonyms,
command: model.commandPrefix || model.command, // either subtree or leaf command
docs: model.command ? model.header : model.title // for leaf commands, print full header
})
}
}
debug('generated top-level usage model')
throw new UsageError({ usage: topLevelUsage })
} else {
debug('no usage model')
const registration: PreloadRegistration = async (commandTree: PreloadRegistrar) => {
const asyncs = []
if (!isHeadless()) {
asyncs.push(import('./lib/cmds/zoom').then(_ => _.preload()))
asyncs.push(import('./lib/new-tab').then(_ => _.default(commandTree)))
asyncs.push(import('./lib/cmds/history/reverse-i-search').then(_ => _.default()))
}
if (!isHeadless() && !inBrowser()) {
// in webpack, use the default text-search bar of browser
asyncs.push(import('./lib/text-search').then(_ => _.default()))
}
return Promise.all(asyncs)
}
const iter = () => {
if (typeof AMDLoader === 'undefined') {
setTimeout(iter, 20)
} else {
if (!amdRequire) {
// Save Monaco's amd require and restore Node's require
amdRequire = global['require']
global['require'] = nodeRequire
if (!inBrowser()) {
const monacoRoot = path.dirname(require.resolve('monaco-editor/package.json'))
amdRequire.config({
baseUrl: uriFromPath(path.join(monacoRoot, 'min'))
})
}
// workaround monaco-css not understanding the environment
self['module'] = undefined
// workaround monaco-typescript not understanding the environment
// self.process.browser = true
}
if (editor) {
return resolve(editor)
const aboutWindow = async (args: Arguments): Promise => {
debug('aboutWindow')
const { parsedOptions, REPL } = args
injectCSS({
css: require('@kui-shell/plugin-core-support/web/css/about.css'),
key: 'about-window-css'
})
const name =
theme.productName ||
(!inBrowser() &&
(await import(/* webpackChunkName: "electron" */ /* webpackMode: "lazy" */ './electron-helpers')).getAppName())
// this is the main container for the dom
const content = document.createElement('div')
content.classList.add('about-window')
const defaultMode = parsedOptions.mode || 'about'
debug('defaultMode', defaultMode)
if (parsedOptions.content) {
const response = await REPL.qexec(parsedOptions.content, undefined, undefined, { render: true })
debug('rendering content', parsedOptions.content, response)
const container = document.createElement('div')
const innerContainer = document.createElement('div')
container.classList.add('about-window-bottom-content')
reject(new Error('Local file access not supported when running in a browser'))
}
// purposefully imported lazily, so that we don't spoil browser mode (where shell is not available)
const shell = await import('shelljs')
if (argv.length < 2) {
reject(new Error('Please provide a bash command'))
}
const cmd = argv[1]
debug('argv', argv)
debug('cmd', cmd)
// shell.echo prints the the outer console, which we don't want
if (shell[cmd] && (inBrowser() || (cmd !== 'mkdir' && cmd !== 'echo'))) {
const args = argv.slice(2)
// remember OLDPWD, so that `cd -` works (shell issue #78)
if (process.env.OLDPWD === undefined) {
process.env.OLDPWD = ''
}
const OLDPWD = shell.pwd() // remember it for when we're done
if (cmd === 'cd' && args[0] === '-') {
// special case for "cd -"
args[0] = process.env.OLDPWD
}
// see if we should use the built-in shelljs support
if (
!args.find(arg => arg.charAt(0) === '-') && // any options? then no
!args.find(arg => arg === '>') && // redirection? then no
export default async (commandTree: Registrar) => {
if (!isHeadless()) {
import('./lib/tab-completion/git').then(_ => _.default())
}
if (!inBrowser()) {
try {
const prefetchShellState = (await import('./pty/prefetch')).default
await prefetchShellState()
debug('done with state prefetch')
} catch (err) {
console.error('error in state prefetch', err)
}
}
return registerCatchAll(commandTree)
}
noAuthOk: true,
requiresLocal: true
})
commandTree.listen('/sendtopty', specialHandler, {
docs: 'Execute a UNIX shell command with a PTY',
noAuthOk: true,
inBrowserOk: true,
hidden: true
})
commandTree.listen('/kuicd', cd, {
noAuthOk: true
})
if (!inBrowser()) {
commandTree.listen('/cd', cd, {
usage: usage.cd,
noAuthOk: true
})
} else {
commandTree.listen('/cd', bcd, {
usage: usage.cd,
noAuthOk: true,
inBrowserOk: true
})
}
}
export default async (commandTree: Registrar) => {
if (!inBrowser()) {
await Promise.all([
commands(commandTree),
compile(commandTree),
install(commandTree),
get(commandTree),
list(commandTree),
home(commandTree),
remove(commandTree),
version(commandTree)
])
}
}