Работа над отображением объектов, работа со стилями, работа с позиционированиме, изменение таблицы переменных

This commit is contained in:
XeRo 2026-01-14 18:08:43 +05:00
parent ada7db46cf
commit 2e8eee135e
7 changed files with 477 additions and 431 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/sirupsen/logrus"
)
type ListApplicationItem struct {
@ -42,9 +43,9 @@ func NewListApplicationsModel(applications []types.PackageApplication, width, he
delegate.Styles.SelectedDesc = ui.ListSelectedStyle
delegate.ShowDescription = false
l := list.New(items, delegate, width, height)
l.Title = "Выберите приложение для настройки"
l.Title = "Приложения"
l.Styles.Title = ui.ListTitleStyle
l.SetShowHelp(false)
return &ListApplicationsModel{
List: l,
width: width,
@ -65,15 +66,13 @@ func (m *ListApplicationsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
return m, tea.Quit
case "enter":
selected := m.List.SelectedItem().(ListApplicationItem)
return m, func() tea.Msg {
return types.ShowModalMsg{
Type: types.ModalConfirm,
Title: "Начать установку",
Message: fmt.Sprintf("Вы хотит настроить приложение:\n\n%s\n\nПродолжить?", selected.Title()),
Message: fmt.Sprintf("Вы хотите настроить приложение:\n\n%s\n\nПродолжить?", selected.Title()),
ModalButtons: []types.ModalButton{
{Text: "Да", Value: true},
{Text: "Нет", Value: false},
@ -95,46 +94,63 @@ func (m *ListApplicationsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
func (m *ListApplicationsModel) View() string {
contentWidth := ui.ContentWidth(m.width)
listWidth := int(float64(contentWidth) * ui.ListWithRatio)
m.List.SetSize(listWidth-6, m.height-10)
gapStroke := " "
containerWidth, containerHeight, contentWidth, contentHeight := ui.ContentSizes(m.width, m.height)
listView := m.List.View()
listWidth := int(float64(contentWidth)*ui.ListWithRatio) - 2*1
//ширина листа = пропорция от ширины контента - границы для контейнера листа
listHeight := contentHeight - 2*1
//высота листа = высота контента - границы для контейнера листа
descWidth := int(float64(contentWidth)*(1-ui.ListWithRatio)) - 2*1 - len(gapStroke)
//ширина описания = обратная пропорция листа от ширины контента - границы для контейнера описания - отступ от контейнера листа
descHeight := contentHeight - 2*1
//высота листа = высота контента - границы для контейнера описания
m.List.SetSize(listWidth, listHeight)
//logs.go logrus.DebugLevel set
logrus.Debugf(
"window: width %d, height %d\ncontainer: width %d, height %d\ncontent: width %d, height %d\nlist: width %d, height %d\ndesc: width %d, height %d\n\n",
m.width, m.height,
containerWidth, containerHeight,
contentWidth, contentHeight,
listWidth, listHeight,
descWidth, descHeight,
)
listView := lipgloss.NewStyle().
Width(listWidth).
Height(listHeight).
Border(lipgloss.RoundedBorder()).
BorderForeground(ui.ColorPurple).
AlignVertical(lipgloss.Top).
Render(m.List.View())
var desc string
if sel := m.List.SelectedItem(); sel != nil {
desc = sel.(ListApplicationItem).Description()
}
descView := ui.ListDescriptionStyle.Width(contentWidth - listWidth - 10).Render(desc)
body := lipgloss.JoinHorizontal(lipgloss.Top, listView, " ", descView)
container := ui.ListContainer.Width(contentWidth).Render(body)
return lipgloss.Place(m.width, m.height,
descView := ui.ListDescriptionStyle.
Width(descWidth).
Height(descHeight).
Border(lipgloss.RoundedBorder()).
BorderForeground(ui.ColorError).
AlignVertical(lipgloss.Top).
Render(
desc,
)
body := lipgloss.JoinHorizontal(lipgloss.Center, listView, gapStroke, descView)
container := ui.AppContainer.
Width(containerWidth).
Height(containerHeight).
Render(body)
return lipgloss.Place(
m.width, m.height,
lipgloss.Center, lipgloss.Center,
container,
lipgloss.WithWhitespaceChars("░"),
lipgloss.WithWhitespaceForeground(ui.ColorGrey),
lipgloss.WithWhitespaceForeground(ui.ColorWarning),
)
//var desc string
//if selected := m.List.SelectedItem(); selected != nil {
// desc = selected.(ListApplicationItem).Description()
//}
//descView := ui.ListDescriptionStyle.
// Width(contentWidth/2 - 4).
// Render(desc)
//
//body := lipgloss.JoinHorizontal(lipgloss.Top, listView, " ", descView)
//
//container := ui.ListStyle.
// Width(contentWidth).
// Render(body)
//
//return lipgloss.Place(m.width, m.height,
// lipgloss.Center, lipgloss.Center,
// container,
// lipgloss.WithWhitespaceChars("░"),
// lipgloss.WithWhitespaceForeground(ui.ColorGrey),
//)
}