ssm-browse: header styling

This commit is contained in:
Leon Mika 2022-03-30 22:52:26 +11:00
parent 798150a403
commit 1b8518b6e4
9 changed files with 76 additions and 28 deletions

View file

@ -14,6 +14,13 @@ import (
"github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/layout" "github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/layout"
) )
var (
activeHeaderStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#4479ff"))
)
type Model struct { type Model struct {
ready bool ready bool
frameTitle frame.FrameTitle frameTitle frame.FrameTitle
@ -27,7 +34,7 @@ type Model struct {
func New() *Model { func New() *Model {
return &Model{ return &Model{
frameTitle: frame.NewFrameTitle("Item", false), frameTitle: frame.NewFrameTitle("Item", false, activeHeaderStyle),
viewport: viewport.New(100, 100), viewport: viewport.New(100, 100),
} }
} }

View file

@ -11,6 +11,13 @@ import (
"github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/layout" "github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/layout"
) )
var (
activeHeaderStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#4479ff"))
)
type Model struct { type Model struct {
frameTitle frame.FrameTitle frameTitle frame.FrameTitle
table table.Model table table.Model
@ -26,7 +33,7 @@ func New() *Model {
rows := make([]table.Row, 0) rows := make([]table.Row, 0)
tbl.SetRows(rows) tbl.SetRows(rows)
frameTitle := frame.NewFrameTitle("No table", true) frameTitle := frame.NewFrameTitle("No table", true, activeHeaderStyle)
return &Model{ return &Model{
frameTitle: frameTitle, frameTitle: frameTitle,

View file

@ -8,25 +8,21 @@ import (
) )
var ( var (
activeHeaderStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#4479ff"))
inactiveHeaderStyle = lipgloss.NewStyle(). inactiveHeaderStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#000000")). Foreground(lipgloss.Color("#000000")).
Background(lipgloss.Color("#d1d1d1")) Background(lipgloss.Color("#d1d1d1"))
) )
// Frame is a frame that appears in the // Frame is a frame that appears in the
type FrameTitle struct { type FrameTitle struct {
header string header string
active bool active bool
width int activeStyle lipgloss.Style
width int
} }
func NewFrameTitle(header string, active bool) FrameTitle { func NewFrameTitle(header string, active bool, activeStyle lipgloss.Style) FrameTitle {
return FrameTitle{header, active, 0} return FrameTitle{header, active, activeStyle, 0}
} }
func (f *FrameTitle) SetTitle(title string) { func (f *FrameTitle) SetTitle(title string) {
@ -48,7 +44,7 @@ func (f FrameTitle) HeaderHeight() int {
func (f FrameTitle) headerView() string { func (f FrameTitle) headerView() string {
style := inactiveHeaderStyle style := inactiveHeaderStyle
if f.active { if f.active {
style = activeHeaderStyle style = f.activeStyle
} }
titleText := f.header titleText := f.header

View file

@ -25,6 +25,11 @@ func newListController(tableNames []string, w, h int) listController {
delegate := list.NewDefaultDelegate() delegate := list.NewDefaultDelegate()
delegate.ShowDescription = false delegate.ShowDescription = false
delegate.Styles.SelectedTitle = lipgloss.NewStyle().
Border(lipgloss.NormalBorder(), false, false, false, true).
BorderForeground(lipgloss.Color("#2c5fb7")).
Foreground(lipgloss.Color("#2c5fb7")).
Padding(0, 0, 0, 1)
list := list.New(items, delegate, w, h) list := list.New(items, delegate, w, h)
list.SetShowTitle(false) list.SetShowTitle(false)

View file

@ -10,6 +10,13 @@ import (
"github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/utils" "github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/utils"
) )
var (
activeHeaderStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#4479ff"))
)
type Model struct { type Model struct {
frameTitle frame.FrameTitle frameTitle frame.FrameTitle
listController listController listController listController
@ -20,7 +27,7 @@ type Model struct {
} }
func New(submodel tea.Model) *Model { func New(submodel tea.Model) *Model {
frameTitle := frame.NewFrameTitle("Select table", false) frameTitle := frame.NewFrameTitle("Select table", false, activeHeaderStyle)
return &Model{frameTitle: frameTitle, submodel: submodel} return &Model{frameTitle: frameTitle, submodel: submodel}
} }

View file

@ -10,21 +10,28 @@ import (
"github.com/lmika/awstools/internal/slog-view/models" "github.com/lmika/awstools/internal/slog-view/models"
) )
var (
activeHeaderStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#9c9c9c"))
)
type Model struct { type Model struct {
frameTitle frame.FrameTitle frameTitle frame.FrameTitle
viewport viewport.Model viewport viewport.Model
w, h int w, h int
// model state // model state
focused bool focused bool
selectedItem *models.LogLine selectedItem *models.LogLine
} }
func New() *Model { func New() *Model {
viewport := viewport.New(0, 0) viewport := viewport.New(0, 0)
viewport.SetContent("") viewport.SetContent("")
return &Model{ return &Model{
frameTitle: frame.NewFrameTitle("Item", false), frameTitle: frame.NewFrameTitle("Item", false, activeHeaderStyle),
viewport: viewport, viewport: viewport,
} }
} }

View file

@ -10,6 +10,13 @@ import (
"path/filepath" "path/filepath"
) )
var (
activeHeaderStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#9c9c9c"))
)
type Model struct { type Model struct {
frameTitle frame.FrameTitle frameTitle frame.FrameTitle
table table.Model table table.Model
@ -20,12 +27,12 @@ type Model struct {
} }
func New() *Model { func New() *Model {
frameTitle := frame.NewFrameTitle("File: ", true) frameTitle := frame.NewFrameTitle("File: ", true, activeHeaderStyle)
table := table.New([]string{"level", "error", "message"}, 0, 0) table := table.New([]string{"level", "error", "message"}, 0, 0)
return &Model{ return &Model{
frameTitle: frameTitle, frameTitle: frameTitle,
table: table, table: table,
} }
} }
@ -92,7 +99,6 @@ func (m *Model) View() string {
func (m *Model) Resize(w, h int) layout.ResizingModel { func (m *Model) Resize(w, h int) layout.ResizingModel {
m.w, m.h = w, h m.w, m.h = w, h
m.frameTitle.Resize(w, h) m.frameTitle.Resize(w, h)
m.table.SetSize(w, h - m.frameTitle.HeaderHeight()) m.table.SetSize(w, h-m.frameTitle.HeaderHeight())
return m return m
} }

View file

@ -11,6 +11,13 @@ import (
"strings" "strings"
) )
var (
activeHeaderStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#c144ff"))
)
type Model struct { type Model struct {
frameTitle frame.FrameTitle frameTitle frame.FrameTitle
viewport viewport.Model viewport viewport.Model
@ -25,7 +32,7 @@ func New() *Model {
viewport := viewport.New(0, 0) viewport := viewport.New(0, 0)
viewport.SetContent("") viewport.SetContent("")
return &Model{ return &Model{
frameTitle: frame.NewFrameTitle("Item", false), frameTitle: frame.NewFrameTitle("Item", false, activeHeaderStyle),
viewport: viewport, viewport: viewport,
} }
} }

View file

@ -9,6 +9,13 @@ import (
"github.com/lmika/awstools/internal/ssm-browse/models" "github.com/lmika/awstools/internal/ssm-browse/models"
) )
var (
activeHeaderStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#ffffff")).
Background(lipgloss.Color("#c144ff"))
)
type Model struct { type Model struct {
frameTitle frame.FrameTitle frameTitle frame.FrameTitle
table table.Model table table.Model
@ -19,12 +26,12 @@ type Model struct {
} }
func New() *Model { func New() *Model {
frameTitle := frame.NewFrameTitle("SSM: /", true) frameTitle := frame.NewFrameTitle("SSM: /", true, activeHeaderStyle)
table := table.New([]string{"name", "type", "value"}, 0, 0) table := table.New([]string{"name", "type", "value"}, 0, 0)
return &Model{ return &Model{
frameTitle: frameTitle, frameTitle: frameTitle,
table: table, table: table,
} }
} }
@ -85,7 +92,6 @@ func (m *Model) View() string {
func (m *Model) Resize(w, h int) layout.ResizingModel { func (m *Model) Resize(w, h int) layout.ResizingModel {
m.w, m.h = w, h m.w, m.h = w, h
m.frameTitle.Resize(w, h) m.frameTitle.Resize(w, h)
m.table.SetSize(w, h - m.frameTitle.HeaderHeight()) m.table.SetSize(w, h-m.frameTitle.HeaderHeight())
return m return m
} }