Работа над стилями, работа над модальными окнами, изменение списка приложений, работа с размерами окон

This commit is contained in:
XeRo 2025-12-29 17:46:48 +05:00
parent 5203032b83
commit ada7db46cf
12 changed files with 1161 additions and 130 deletions

View file

@ -17,34 +17,54 @@ func Start() {
type Main struct {
current tea.Model
overlay tea.Model
Applications []types.PackageApplication
CurrentApplication *types.PackageApplication
CurrentSection *types.Section
CurrentSectionIdx int
width int
height int
Width int
Height int
}
func NewMain() *Main {
apps := bootstrap.LoadApplications()
return &Main{
m := &Main{
Applications: apps,
current: NewListModel(apps),
CurrentSectionIdx: 0,
}
m.current = NewListApplicationsModel(m.Applications, m.Width, m.Height)
return m
}
func (m *Main) Init() tea.Cmd {
return m.current.Init()
}
func (m *Main) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
m.current, cmd = m.current.Update(msg)
var cmds []tea.Cmd
if m.overlay != nil {
var cmd tea.Cmd
m.overlay, cmd = m.overlay.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
} else {
var cmd tea.Cmd
m.current, cmd = m.current.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
}
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
m.current, cmd = m.current.Update(msg)
m.Width = msg.Width
m.Height = msg.Height
if m.current != nil {
m.current, _ = m.current.Update(msg)
}
if m.overlay != nil {
m.overlay, _ = m.overlay.Update(msg)
}
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
@ -65,21 +85,31 @@ func (m *Main) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
if m.CurrentSection == nil {
logrus.Infof("next section, eq nil, out, idx %d", m.CurrentSectionIdx)
return m, tea.Quit
return m, func() tea.Msg {
return types.ShowModalMsg{
Type: types.ModalError,
Title: "Ошибка конфигурации",
Message: "Это приложение не имеет доступных секций для настройки\n" +
"Возможно оно повреждено или не поддерживается",
ModalButtons: []types.ModalButton{{Text: "Выйти", Value: true}},
OnResult: func(result any) tea.Cmd {
return tea.Quit
},
}
}
}
//todo переделать. Учесть динамические индексы.
if m.CurrentSectionIdx == len(m.CurrentApplication.Sections)-1 && m.CurrentSection.Type == "final" {
m.current = NewFinalModel(m.CurrentApplication.Variables, m.width, m.height)
if m.CurrentSectionIdx == len(m.CurrentApplication.Sections)-1 && m.CurrentSection.Type == types.SectionFinal {
m.current = NewFinalModel(m.CurrentApplication.Variables, m.Width, m.Height)
} else {
m.current = NewFormModel(m.CurrentApplication, m.CurrentSectionIdx, 0)
m.current = NewFormModel(m.CurrentApplication, m.CurrentSectionIdx, 0, m.Width, m.Height)
}
case types.SugarMsg:
m.Sugar(msg)
case types.SelectedAppMsg:
//получаем сообщение о выборе приложения
m.CurrentApplication = &m.Applications[msg.Index]
m.CurrentApplication = &msg.App
//ищем доступную секцию
for sectionIdx := 0; sectionIdx < len(m.CurrentApplication.Sections); sectionIdx++ {
@ -96,13 +126,29 @@ func (m *Main) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit
}
//создаем новую форму
m.current = NewFormModel(m.CurrentApplication, m.CurrentSectionIdx, 0)
m.current = NewFormModel(m.CurrentApplication, m.CurrentSectionIdx, 0, m.Width, m.Height)
case types.BackToListMsg:
m.CurrentApplication = nil
m.CurrentSection = nil
m.CurrentSectionIdx = 0
m.current = NewListApplicationsModel(m.Applications, m.Width, m.Height)
case types.ShowModalMsg:
m.overlay = NewModalModel(msg, m.Width, m.Height)
return m, nil
case types.CloseModalMsg:
logrus.Infof("modal close msg get")
m.overlay = nil
return m, tea.Batch(cmds...)
}
return m, cmd
return m, tea.Batch(cmds...)
}
func (m *Main) View() string {
return m.current.View()
view := m.current.View()
if m.overlay != nil {
view = m.overlay.View()
}
return view
}
func (m *Main) Sugar(sugar types.SugarMsg) {
@ -113,7 +159,7 @@ func (m *Main) Sugar(sugar types.SugarMsg) {
if sugar.Compute != "" {
Recompute(m.CurrentApplication)
}
m.current = NewFormModel(m.CurrentApplication, m.CurrentSectionIdx, sugar.Focus)
m.current = NewFormModel(m.CurrentApplication, m.CurrentSectionIdx, sugar.Focus, m.Width, m.Height)
}
}