Skip to content

Commit

Permalink
Merge pull request #52 from ewilliams0305/banner
Browse files Browse the repository at this point in the history
Banner
  • Loading branch information
ewilliams0305 committed Dec 30, 2023
2 parents 58872f2 + bd65a73 commit 60641f7
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 11 deletions.
7 changes: 6 additions & 1 deletion pkg/tui/actions_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ActionsModel struct {
action initialAction
progress progress.Model
results *actionResult
banner *BannerModel
}

type actionResult struct {
Expand Down Expand Up @@ -58,6 +59,7 @@ func InitialActionModel(message string, action initialAction) *ActionsModel {
action: action,
err: nil,
progress: prog,
banner: NewBanner("VCLI Quick Action", 0, w),
}
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
68 changes: 68 additions & 0 deletions pkg/tui/banner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package tui

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

const (
BannerNormalState BannerState = iota
BannerErrorState BannerState = 1
)

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
case error:
m.state = BannerErrorState
m.message = msg.Error()
}
return m, nil
}

func (m BannerModel) View() string {
return renderBanner(m)
}

func renderBanner(model BannerModel) string {
var bg lipgloss.Color
if model.state == BannerNormalState {
bg = lipgloss.Color(PrimaryDark)
} else {
bg = lipgloss.Color(ErrorColor)
}

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")
}
8 changes: 4 additions & 4 deletions pkg/tui/programs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ProgramsModel struct {
help programsHelpModel
busy busy
cursor int
banner *BannerModel
width, height int
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
)

Expand Down
7 changes: 5 additions & 2 deletions pkg/tui/rooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type RoomsTableModel struct {
busy busy
cursor int
width, height int
banner *BannerModel
}

func InitialRoomsModel(width, height int) *RoomsTableModel {
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
)

Expand Down
13 changes: 9 additions & 4 deletions pkg/tui/service_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type VirtualControlServiceModel struct {
help SystemsHelpModel
list list.Model
progress progress.Model
banner *BannerModel
}

type serviceOption struct {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)

}
}
Expand Down Expand Up @@ -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))
}
Expand All @@ -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"

Expand Down

0 comments on commit 60641f7

Please sign in to comment.