github.com/wolfi-dev/wolfictl@v0.16.11/pkg/cli/components/textinput/textinput.go (about)

     1  package textinput
     2  
     3  import (
     4  	"github.com/charmbracelet/bubbles/textinput"
     5  	tea "github.com/charmbracelet/bubbletea"
     6  )
     7  
     8  // Model wraps Charm's textinput.Model to make it an actual tea.Model.
     9  //
    10  // I'm not 100% sure why this is necessary, so I've asked on an issue:
    11  // https://github.com/charmbracelet/bubbles/issues/371#issuecomment-2062787557.
    12  type Model struct {
    13  	Inner textinput.Model
    14  }
    15  
    16  // New returns a new text input model.
    17  func New() Model {
    18  	ti := textinput.New()
    19  	ti.Focus()
    20  
    21  	return Model{
    22  		Inner: ti,
    23  	}
    24  }
    25  
    26  func (m Model) Init() tea.Cmd {
    27  	return textinput.Blink
    28  }
    29  
    30  func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
    31  	var cmd tea.Cmd
    32  	m.Inner, cmd = m.Inner.Update(msg)
    33  	return m, cmd
    34  }
    35  
    36  func (m Model) View() string {
    37  	return m.Inner.View()
    38  }