/ components / PromptInput / inputModes.ts
inputModes.ts
 1  import type { HistoryMode } from 'src/hooks/useArrowKeyHistory.js'
 2  import type { PromptInputMode } from 'src/types/textInputTypes.js'
 3  
 4  export function prependModeCharacterToInput(
 5    input: string,
 6    mode: PromptInputMode,
 7  ): string {
 8    switch (mode) {
 9      case 'bash':
10        return `!${input}`
11      default:
12        return input
13    }
14  }
15  
16  export function getModeFromInput(input: string): HistoryMode {
17    if (input.startsWith('!')) {
18      return 'bash'
19    }
20    return 'prompt'
21  }
22  
23  export function getValueFromInput(input: string): string {
24    const mode = getModeFromInput(input)
25    if (mode === 'prompt') {
26      return input
27    }
28    return input.slice(1)
29  }
30  
31  export function isInputModeCharacter(input: string): boolean {
32    return input === '!'
33  }