From 727e5e94b9790f5c990047cb0e1345cefb1af332 Mon Sep 17 00:00:00 2001 From: Eric Williams Date: Fri, 29 Dec 2023 22:08:16 -0500 Subject: [PATCH 1/5] Create banner.go --- pkg/tui/banner.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 pkg/tui/banner.go diff --git a/pkg/tui/banner.go b/pkg/tui/banner.go new file mode 100644 index 0000000..ab41069 --- /dev/null +++ b/pkg/tui/banner.go @@ -0,0 +1,61 @@ +package tui + +import ( + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" +) + +type BannerModel struct { + message string + state BannerState + width int +} + +type BannerState int + +func (m BannerModel) Init() tea.Cmd { + return nil +} + +func NewBanner(message string, state BannerState, width int) *BannerModel { + return &BannerModel{ + message: message, + state: state, + width: width, + } +} + +func (m BannerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case BannerState: + m.state = msg + case string: + m.message = msg + } + + return m, nil +} + +func (m BannerModel) View() string { + return renderBanner(&m) +} + +func renderBanner(model *BannerModel) string { + var bg lipgloss.Color + if model.state == 0 { + bg = lipgloss.Color(PrimaryDark) + } else { + bg = lipgloss.Color("#FF0000") + } + + return lipgloss.NewStyle(). + Bold(true). + Foreground(lipgloss.Color(PrimaryLight)). + Background(lipgloss.Color(bg)). + PaddingTop(1). + PaddingLeft(1). + MarginBottom(1). + Width(model.width). + Align(lipgloss.Center). + Render(model.message) + "\n\n" +} From bd76ca50e5f92ff74283ab769c5cf39a2c18639c Mon Sep 17 00:00:00 2001 From: Eric Williams Date: Fri, 29 Dec 2023 22:29:02 -0500 Subject: [PATCH 2/5] added error to banner banner can now change colors when the banner state changes --- pkg/tui/actions_model.go | 7 ++++++- pkg/tui/banner.go | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/tui/actions_model.go b/pkg/tui/actions_model.go index f2cacf0..414efae 100644 --- a/pkg/tui/actions_model.go +++ b/pkg/tui/actions_model.go @@ -26,6 +26,7 @@ type ActionsModel struct { action initialAction progress progress.Model results *actionResult + banner *BannerModel } type actionResult struct { @@ -58,6 +59,7 @@ func InitialActionModel(message string, action initialAction) *ActionsModel { action: action, err: nil, progress: prog, + banner: NewBanner("VCLI Quick Action", 0, w), } } @@ -96,6 +98,8 @@ func (m ActionsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case error: m.err = msg + m.banner = NewBanner(m.message, BannerErrorState, m.progress.Width) + return m, nil case vc.ProgramUploadResult: @@ -140,7 +144,8 @@ func (m ActionsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m ActionsModel) View() string { - s := "\n" + m.message + "\n" + s := m.banner.View() + s += "\n" + m.message + "\n" if m.progress.Percent() != 0.0 { s += "\n" + m.progress.View() + "\n\n" diff --git a/pkg/tui/banner.go b/pkg/tui/banner.go index ab41069..3d3e618 100644 --- a/pkg/tui/banner.go +++ b/pkg/tui/banner.go @@ -5,6 +5,11 @@ import ( "github.com/charmbracelet/lipgloss" ) +const ( + BannerNormalState BannerState = iota + BannerErrorState BannerState = 1 +) + type BannerModel struct { message string state BannerState @@ -31,21 +36,23 @@ func (m BannerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.state = msg case string: m.message = msg + case error: + m.state = BannerErrorState + m.message = msg.Error() } - return m, nil } func (m BannerModel) View() string { - return renderBanner(&m) + return renderBanner(m) } -func renderBanner(model *BannerModel) string { +func renderBanner(model BannerModel) string { var bg lipgloss.Color - if model.state == 0 { + if model.state == BannerNormalState { bg = lipgloss.Color(PrimaryDark) } else { - bg = lipgloss.Color("#FF0000") + bg = lipgloss.Color(ErrorColor) } return lipgloss.NewStyle(). @@ -57,5 +64,5 @@ func renderBanner(model *BannerModel) string { MarginBottom(1). Width(model.width). Align(lipgloss.Center). - Render(model.message) + "\n\n" + Render(model.message + "\n") } From a076c9dd968cf9ac28fa4ac4acc9ea032a21a442 Mon Sep 17 00:00:00 2001 From: Eric Williams Date: Fri, 29 Dec 2023 22:36:40 -0500 Subject: [PATCH 3/5] added banner to programs --- pkg/tui/programs.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/tui/programs.go b/pkg/tui/programs.go index 1971215..5ec748f 100644 --- a/pkg/tui/programs.go +++ b/pkg/tui/programs.go @@ -22,6 +22,7 @@ type ProgramsModel struct { help programsHelpModel busy busy cursor int + banner *BannerModel width, height int } @@ -34,6 +35,7 @@ func InitialProgramsModel(width, height int) *ProgramsModel { help: NewProgramsHelpModel(), width: width, height: height, + banner: NewBanner("MANAGE PROGRAM LIBRARY", BannerNormalState, width), } return programsView } @@ -72,8 +74,6 @@ func (m ProgramsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.width = w m.height = h } - - // TODO: handle the errors and stop the polling return m, tea.Batch(ProgramsQuery, tick) case tea.WindowSizeMsg: @@ -166,7 +166,7 @@ func (m ProgramsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m ProgramsModel) View() string { - s := DisplayLogo(m.width) + s := m.banner.View() + "\n" s += BaseStyle.Render(m.table.View()) + "\n\n" if m.busy.flag { @@ -194,7 +194,7 @@ func newProgramsTable(Programs vc.Programs, cursor int, width int) table.Model { table.WithColumns(columns), table.WithRows(rows), table.WithFocused(false), - table.WithHeight(9), + table.WithHeight(16), table.WithWidth(width), ) From 861889b9a2c225e7453a6b4f6ed2fbec2a121652 Mon Sep 17 00:00:00 2001 From: Eric Williams Date: Fri, 29 Dec 2023 22:42:22 -0500 Subject: [PATCH 4/5] added banner to rooms --- pkg/tui/rooms.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/tui/rooms.go b/pkg/tui/rooms.go index cb5330d..7b6afeb 100644 --- a/pkg/tui/rooms.go +++ b/pkg/tui/rooms.go @@ -24,6 +24,7 @@ type RoomsTableModel struct { busy busy cursor int width, height int + banner *BannerModel } func InitialRoomsModel(width, height int) *RoomsTableModel { @@ -34,6 +35,7 @@ func InitialRoomsModel(width, height int) *RoomsTableModel { help: NewRoomsHelpModel(), width: width, height: height, + banner: NewBanner("MANAGE RUNNING INSTANCES", BannerNormalState, width), } return roomsModel } @@ -46,6 +48,7 @@ func ReturnRoomsModel() *RoomsTableModel { help: NewRoomsHelpModel(), width: app.width, height: app.width, + banner: NewBanner("MANAGE RUNNING INSTANCES", BannerNormalState, app.width), } return roomsModel } @@ -167,7 +170,7 @@ func (m RoomsTableModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m RoomsTableModel) View() string { - s := DisplayLogo(m.width) + s := m.banner.View() + "\n" s += BaseStyle.Render(m.table.View()) + "\n\n" if m.busy.flag { @@ -190,7 +193,7 @@ func newRoomsTable(rooms vc.Rooms, cursor int, width int) table.Model { table.WithColumns(columns), table.WithRows(rows), table.WithFocused(false), - table.WithHeight(9), + table.WithHeight(16), table.WithWidth(width), ) From bd65a738fd3721a8e705dc9b8f9120caeb185230 Mon Sep 17 00:00:00 2001 From: Eric Williams Date: Fri, 29 Dec 2023 22:52:38 -0500 Subject: [PATCH 5/5] added banner to services closes #51 --- pkg/tui/service_exec.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/tui/service_exec.go b/pkg/tui/service_exec.go index c11be0e..27b5c2a 100644 --- a/pkg/tui/service_exec.go +++ b/pkg/tui/service_exec.go @@ -16,6 +16,7 @@ type VirtualControlServiceModel struct { help SystemsHelpModel list list.Model progress progress.Model + banner *BannerModel } type serviceOption struct { @@ -49,6 +50,7 @@ func InitialSystemModel() VirtualControlServiceModel { altscreenActive: true, list: list.New(items, list.NewDefaultDelegate(), 100, 20), progress: prog, + banner: NewBanner("MANAGE VIRTUAL CONTROL SERVICE", BannerNormalState, app.width), } m.list.Title = "Virtual Control Service Actions" @@ -78,7 +80,8 @@ func (m VirtualControlServiceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case "l", "ctrl+l": if m.list.FilterState() != list.Filtering { - return m, tea.Batch(openJournal(), tea.EnterAltScreen) + return m, openJournal() + // return m, tea.Batch(openJournal(), tea.EnterAltScreen) } case "esc", "ctrl+q", "q": if m.list.FilterState() != list.Filtering { @@ -95,7 +98,8 @@ func (m VirtualControlServiceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case 2: return m, tea.Batch(restartService(), systemTickCmd()) case 3: - return m, tea.Batch(openJournal(), tea.EnterAltScreen) + return m, openJournal() + // return m, tea.Batch(openJournal(), tea.EnterAltScreen) } } @@ -126,7 +130,8 @@ func (m VirtualControlServiceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case progressTick: if m.progress.Percent() == 1.0 { m.progress.SetPercent(0) - return m, tea.Batch(openJournal(), tea.EnterAltScreen) + // return m, tea.Batch(openJournal(), tea.EnterAltScreen) + return m, openJournal() } return m, tea.Batch(systemTickCmd(), m.progress.IncrPercent(0.20)) } @@ -137,7 +142,7 @@ func (m VirtualControlServiceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m VirtualControlServiceModel) View() string { - s := "\n" + s := m.banner.View() + "\n" s += docStyle.Render(m.list.View()) s += "\n\n\n"