Работа над viewport формы, добавление описания для поля формы, комментарии к fileSelect модели
This commit is contained in:
parent
ecc89e34c5
commit
c7ff7662ba
9 changed files with 333 additions and 207 deletions
|
|
@ -7,18 +7,22 @@ import (
|
|||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
// InputModel структура описывающая модель поля ввода данных
|
||||
type InputModel struct {
|
||||
label string
|
||||
input textinput.Model
|
||||
label string
|
||||
description string
|
||||
input textinput.Model
|
||||
}
|
||||
|
||||
func NewInputModel(label, value string) *InputModel {
|
||||
// NewInputModel создает новую модель поля ввода данных
|
||||
func NewInputModel(label, value, description string) *InputModel {
|
||||
t := textinput.New()
|
||||
t.SetValue(value)
|
||||
t.Cursor.SetMode(cursor.CursorBlink)
|
||||
return &InputModel{
|
||||
label: label,
|
||||
input: t,
|
||||
label: label,
|
||||
description: description,
|
||||
input: t,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +30,7 @@ func (m *InputModel) Init() tea.Cmd {
|
|||
return textinput.Blink
|
||||
}
|
||||
|
||||
// Update отслеживает действия с полем
|
||||
func (m *InputModel) Update(msg tea.Msg) (FieldModel, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
m.input, cmd = m.input.Update(msg)
|
||||
|
|
@ -34,6 +39,9 @@ func (m *InputModel) Update(msg tea.Msg) (FieldModel, tea.Cmd) {
|
|||
|
||||
func (m *InputModel) View() string {
|
||||
res := fmt.Sprintf("%s: %v", m.label, m.input.View())
|
||||
if m.description != "" {
|
||||
res += fmt.Sprintf("\n%s", m.description)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue