GoSetup-bubble/setup/fields/compute.go

57 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package fields
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
)
// ComputeModel структура описывающая модель вывода вычисляемых значений
type ComputeModel struct {
label string //Имя поля
description string //Описание поля
value string //Значение поля
}
// NewComputeModel создаем новую модель вывода вычисляемых значений
func NewComputeModel(label, value, description string) *ComputeModel {
return &ComputeModel{
label: label,
description: description,
value: value,
}
}
func (m *ComputeModel) Init() tea.Cmd {
return nil
}
// Update отслеживает действия с полем. Так как поле нужно только для вывода, никаких действий не выполняем.
func (m *ComputeModel) Update(msg tea.Msg) (FieldModel, tea.Cmd) {
return m, nil
}
func (m *ComputeModel) View() string {
res := fmt.Sprintf("%s: %s", m.label, m.value)
if m.description != "" {
res += fmt.Sprintf("\n%s", m.description)
}
return res
}
func (m *ComputeModel) Focus() {}
func (m *ComputeModel) Blur() {
}
func (m *ComputeModel) CaptureKeys() bool {
return false
}
func (m *ComputeModel) GetLabel() string {
return m.label
}
func (m *ComputeModel) GetValue() interface{} {
return m.value
}