Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async (commandTree: Registrar, options?) => {
await Promise.all([
help(commandTree, options),
openui(commandTree),
quit(commandTree),
clear(commandTree),
base64(commandTree),
prompt(commandTree),
sleep(commandTree),
history(commandTree),
confirm(commandTree)
])
if (!isHeadless()) {
await Promise.all([
import('./lib/cmds/zoom').then(_ => _.plugin(commandTree)),
import('./lib/cmds/window').then(_ => _.default(commandTree)),
import('./lib/cmds/theme').then(_ => _.plugin(commandTree))
])
}
// updater(commandTree) <-- disabled for now
}
createOutputStream
}: Arguments) => {
/** trim the first part of "/bin/sh: someNonExistentCommand: command not found" */
const cleanUpError = (err: Error) => {
if (err.message && typeof err.message === 'string') {
err.message = err.message.replace(/[a-zA-Z0-9/]+:\s*/, '').trim()
}
throw err
}
const eOptions =
execOptions.raw || execOptions.isProxied
? execOptions
: Object.assign({}, { stdout: await createOutputStream() }, execOptions)
if (isHeadless() || (!inBrowser() && execOptions.raw)) {
const { doExec } = await import(/* webpackMode: "weak" */ './bash-like')
const response = await doExec(command.replace(/^! /, ''), eOptions).catch(cleanUpError)
if (execOptions.raw && typeof response === 'string') {
try {
return JSON.parse(response)
} catch (err) {
debug('response maybe is not JSON', response)
}
}
return response
} else {
const { doExec } = await import(/* webpackMode: "lazy" */ '../../pty/client')
return doExec(
tab,
block as HTMLElement,
command.replace(/^(!|sendtopty)\s+/, ''),
} else if (suffix === 'pkl' || suffix === 'sab') {
throw new Error('Opening of binary files not supported')
} else {
const stats = (await REPL.rexec(`fstat ${REPL.encodeComponent(filepath)} --with-data`)).content
if (stats.isDirectory) {
debug('trying to open a directory; delegating to ls')
return REPL.qexec(`ls ${REPL.encodeComponent(filepath)}`)
} else {
const enclosingDirectory = dirname(filepath)
let data: string | Element = stats.data
let name = basename(filepath)
let packageName = enclosingDirectory === '.' ? undefined : enclosingDirectory
if ((suffix === 'adoc' || suffix === 'md') && !isHeadless()) {
const { title, body } = await markdownify(tab, suffix, data, fullpath)
data = body
if (title) {
// use the first <h1> as the sidecar title
// and use the filename as the "packageName" subtitle
packageName = name
name = title.innerText
}
}
return {
type: 'custom',
kind: 'file',
metadata: {</h1>
export default () => {
if (!isHeadless()) {
// NOTE how there is no await; this is because our goal is only to
// prefetch it
setTimeout(() => {
import('./lib/preload').then(_ => _.default())
}, 500)
return import('./lib/editor-provider').then(_ => _.default())
}
}
// 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 {
const clear = ({ parsedOptions, tab }: Arguments) => {
if (!isHeadless()) {
if (!parsedOptions.k) {
// don't keep the current active prompt
debug('clearing everything, the repl loop will set up the next prompt for us')
empty(tab.querySelector('.repl-inner'))
// abort the jobs for the current tab
const tabState = tab.state
tabState.abortAllJobs()
} else {
// keep the current active prompt
debug('preserving the current active prompt')
const selector = '.repl-inner .repl-block:not(.repl-active):not(.processing)'
const blocks = tab.querySelectorAll(selector)
for (let idx = 0; idx < blocks.length; idx++) {
blocks[idx].parentNode.removeChild(blocks[idx])
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)
}
public async stop(withBlank = false) {
this.spinner.clear()
if (withBlank) {
await this.next('')
this.spinner.stopAndPersist({ symbol: '' })
} else {
await this.succeed()
}
if (isHeadless()) {
await this.stdout('\n')
}
}
export default () => {
if (!isHeadless()) {
;(document.querySelector('#help-button') as HTMLElement).onclick = async () => {
const { internalBeCarefulPExec: pexec } = await import('@kui-shell/core')
pexec('about')
}
}
}
public async _write(chunk: Buffer, enc: string, next: (error?: Error | null) => void) {
if (isHeadless()) {
const str = chunk.toString()
await this.stdout(str.substring(0, str.indexOf('\n')), this.killLine)
} else {
const str = chunk.toString()
const splitIdx = str[0] === '\u001b' ? str.indexOf('m', 1) + 2 : 1
const spinnerPart = str[splitIdx - 1]
const restPart = str[splitIdx] === '\u001b' ? str.slice(splitIdx + 5) : str.slice(splitIdx)
const line = document.createElement('pre')
const spinnerDom = document.createElement('div')
const restDom = document.createElement('div')
line.appendChild(spinnerDom)
line.appendChild(restDom)
line.classList.add('flex-layout')
restDom.classList.add('do-not-overflow')