MCPcopy
hub / github.com/mathaou/termdbms / View

Method View

tuiutil/textinput.go:692–726  ·  view source on GitHub ↗

View renders the textinput in its current state.

()

Source from the content-addressed store, hash-verified

690
691// View renders the textinput in its current state.
692func (m TextInputModel) View() string {
693 // Placeholder text
694 if len(m.value) == 0 && m.Placeholder != "" {
695 return m.placeholderView()
696 }
697
698 styleText := m.TextStyle.Inline(true).Render
699
700 value := m.value[m.Offset:m.OffsetRight]
701 pos := max(0, m.pos-m.Offset)
702 v := styleText(m.echoTransform(string(value[:pos])))
703
704 if pos < len(value) {
705 if Ascii {
706 v += "¦"
707 }
708 v += m.cursorView(m.echoTransform(string(value[pos]))) // cursor and text under it
709 v += styleText(m.echoTransform(string(value[pos+1:]))) // text after cursor
710 } else {
711 v += m.cursorView(" ")
712 }
713
714 // If a max width and background color were set fill the empty spaces with
715 // the background color.
716 valWidth := rw.StringWidth(string(value))
717 if m.Width > 0 && valWidth <= m.Width {
718 padding := max(0, m.Width-valWidth)
719 if valWidth+padding <= m.Width && pos < len(value) {
720 padding++
721 }
722 v += styleText(strings.Repeat(" ", padding))
723 }
724
725 return m.PromptStyle.Render(m.Prompt) + v
726}
727
728// placeholderView returns the prompt and placeholder view, if any.
729func (m TextInputModel) placeholderView() string {

Callers

nothing calls this directly

Calls 5

placeholderViewMethod · 0.95
echoTransformMethod · 0.95
cursorViewMethod · 0.95
maxFunction · 0.70
RenderMethod · 0.65

Tested by

no test coverage detected