How to use the @kui-shell/core.isHeadless function in @kui-shell/core

To help you get started, we’ve selected a few @kui-shell/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / kui / plugins / plugin-core-support / src / plugin.ts View on Github external
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
}
github IBM / kui / plugins / plugin-bash-like / src / lib / cmds / catchall.ts View on Github external
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+/, ''),
github IBM / kui / plugins / plugin-bash-like / src / lib / cmds / open.ts View on Github external
} 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>
github IBM / kui / plugins / plugin-editor / src / preload.ts View on Github external
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())
  }
}
github IBM / kui / plugins / plugin-core-support / src / lib / cmds / help.ts View on Github external
// 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 {
github IBM / kui / plugins / plugin-core-support / src / lib / cmds / clear.ts View on Github external
const clear = ({ parsedOptions, tab }: Arguments) =&gt; {
  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 &lt; blocks.length; idx++) {
        blocks[idx].parentNode.removeChild(blocks[idx])
github IBM / kui / plugins / plugin-bash-like / src / preload.ts View on Github external
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)
}
github IBM / kui / plugins / plugin-manager / src / util / ora.ts View on Github external
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')
    }
  }
github IBM / kui / plugins / plugin-core-support / about / src / preload.ts View on Github external
export default () => {
  if (!isHeadless()) {
    ;(document.querySelector('#help-button') as HTMLElement).onclick = async () => {
      const { internalBeCarefulPExec: pexec } = await import('@kui-shell/core')
      pexec('about')
    }
  }
}
github IBM / kui / plugins / plugin-manager / src / util / ora.ts View on Github external
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')