π File detail
components/PromptInput/utils.ts
π§© .tsπ 61 linesπΎ 1,744 bytesπ text
β Back to All Filesπ― Use case
This file lives under βcomponents/β, which covers shared React UI pieces. On the API surface it exposes isVimModeEnabled, getNewlineInstructions, and isNonSpacePrintable β mainly functions, hooks, or classes. It composes internal code from commands and ink (relative imports).
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
import { hasUsedBackslashReturn, isShiftEnterKeyBindingInstalled, } from '../../commands/terminalSetup/terminalSetup.js' import type { Key } from '../../ink.js'
π€ Exports (heuristic)
isVimModeEnabledgetNewlineInstructionsisNonSpacePrintable
π₯οΈ Source preview
import {
hasUsedBackslashReturn,
isShiftEnterKeyBindingInstalled,
} from '../../commands/terminalSetup/terminalSetup.js'
import type { Key } from '../../ink.js'
import { getGlobalConfig } from '../../utils/config.js'
import { env } from '../../utils/env.js'
/**
* Helper function to check if vim mode is currently enabled
* @returns boolean indicating if vim mode is active
*/
export function isVimModeEnabled(): boolean {
const config = getGlobalConfig()
return config.editorMode === 'vim'
}
export function getNewlineInstructions(): string {
// Apple Terminal on macOS uses native modifier key detection for Shift+Enter
if (env.terminal === 'Apple_Terminal' && process.platform === 'darwin') {
return 'shift + β for newline'
}
// For iTerm2 and VSCode, show Shift+Enter instructions if installed
if (isShiftEnterKeyBindingInstalled()) {
return 'shift + β for newline'
}
// Otherwise show backslash+return instructions
return hasUsedBackslashReturn()
? '\\β for newline'
: 'backslash (\\) + return (β) for newline'
}
/**
* True when the keystroke is a printable character that does not begin
* with whitespace β i.e., a normal letter/digit/symbol the user typed.
* Used to gate the lazy space inserted after an image pill.
*/
export function isNonSpacePrintable(input: string, key: Key): boolean {
if (
key.ctrl ||
key.meta ||
key.escape ||
key.return ||
key.tab ||
key.backspace ||
key.delete ||
key.upArrow ||
key.downArrow ||
key.leftArrow ||
key.rightArrow ||
key.pageUp ||
key.pageDown ||
key.home ||
key.end
) {
return false
}
return input.length > 0 && !/^\s/.test(input) && !input.startsWith('\x1b')
}