MCPcopy Create free account
hub / github.com/Effect-TS/effect / renderTextInput

Function renderTextInput

packages/effect/src/cli/Prompt.ts:3747–3792  ·  view source on GitHub ↗
(
  nextState: TextState,
  options: TextOptionsReq,
  theme: Theme,
  submitted: boolean,
  renderOptions?: RenderOptions | undefined
)

Source from the content-addressed store, hash-verified

3745})
3746
3747const renderTextInput = (
3748 nextState: TextState,
3749 options: TextOptionsReq,
3750 theme: Theme,
3751 submitted: boolean,
3752 renderOptions?: RenderOptions | undefined
3753) => {
3754 const text = nextState.value
3755 if (renderOptions?.plain === true) {
3756 switch (options.type) {
3757 case "hidden": {
3758 return ""
3759 }
3760 case "password": {
3761 return theme.passwordMask.repeat(text.length)
3762 }
3763 case "text": {
3764 return text
3765 }
3766 }
3767 }
3768
3769 if (text.length === 0) {
3770 // Avoid wrapping an empty value in ANSI codes, which would make renderPrompt
3771 // add spacing for content that occupies no terminal columns.
3772 return ""
3773 }
3774
3775 const annotation = Option.isSome(nextState.error) ?
3776 theme.errorColor
3777 : submitted ?
3778 theme.submittedColor
3779 : Ansi.combine(Ansi.underlined, theme.primaryColor)
3780
3781 switch (options.type) {
3782 case "hidden": {
3783 return ""
3784 }
3785 case "password": {
3786 return annotateSymbol(theme, theme.passwordMask.repeat(text.length), annotation)
3787 }
3788 case "text": {
3789 return Ansi.annotate(theme.colors, text, annotation)
3790 }
3791 }
3792}
3793
3794const renderTextError = (
3795 nextState: TextState,

Callers 1

renderTextOutputFunction · 0.85

Calls 3

annotateSymbolFunction · 0.85
combineMethod · 0.65
annotateMethod · 0.65

Tested by

no test coverage detected