1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-06-23 06:35:24 +00:00
neonmodem/ui/header/header.go
2023-01-04 23:59:59 -05:00

100 lines
6.5 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package header
import (
"fmt"
"github.com/mrusme/gobbs/config"
"github.com/mrusme/gobbs/ui/ctx"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var (
highlight = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}
banner = "▄▗▖▎▄▗▅▖▗▅▅▖▗▅▅▖▅▅▅▖▏▉▅▅┓▅▖▎▗▅▌\n" +
"▗▎▍▄▗▗▎▏▍▝▝▘▍▝▂▉┈▂▎▍▅▋▊▂╴▏▊▗╴▋▎\n" +
"▊▉▌╴▘▁▏▏▅▆┈▏▉▇▆▌▗▖▍▎▃▎▎▅▋▋▎▗▎▍▘\n" +
"▝▄▄▄▘▇▄▆▄▄▄▝▄▄▘▝▘▝▘▏╴▄▘▄▝▘▇╴▄▘▄\n" +
" v" + config.VERSION
)
type Model struct {
ctx *ctx.Ctx
spinner spinner.Model
}
func NewModel(c *ctx.Ctx) Model {
m := Model{
ctx: c,
}
m.spinner = spinner.New()
m.spinner.Spinner = spinner.Dot
m.spinner.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
return m
}
func (m Model) Init() tea.Cmd {
return m.spinner.Tick
}
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
var cmds []tea.Cmd
if m.ctx.Loading == true {
cmds = append(cmds, m.spinner.Tick)
} else {
return m, nil
}
switch msg := msg.(type) {
case spinner.TickMsg:
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
cmds = append(cmds, cmd)
}
return m, tea.Batch(cmds...)
}
func (m Model) View() string {
var row string
var spinner string = ""
selector := lipgloss.NewStyle().
Foreground(lipgloss.Color("#7fffd4")).
BorderForeground(lipgloss.Color("#7fffd4")).
Border(lipgloss.NormalBorder()).
Padding(0, 1, 0, 1).
Width(40)
curSysIdx := m.ctx.GetCurrentSystem()
var currentSystem string = "All"
if curSysIdx >= 0 {
currentSystem = (*m.ctx.Systems[curSysIdx]).Title()
}
systemSelector := selector.Render(fmt.Sprintf("⏷ %s", currentSystem))
forumSelector := selector.Render("⏷ All")
selectorColumn := lipgloss.JoinVertical(lipgloss.Center,
lipgloss.JoinHorizontal(lipgloss.Bottom, "System: \n "+
lipgloss.NewStyle().Foreground(m.ctx.Theme.DialogBox.Bottombar.GetForeground()).Render("c-s"),
systemSelector),
lipgloss.JoinHorizontal(lipgloss.Bottom, "Forum: \n "+
lipgloss.NewStyle().Foreground(m.ctx.Theme.DialogBox.Bottombar.GetForeground()).Render("c-f"),
forumSelector),
)
if m.ctx.Loading == true {
spinner = m.spinner.View()
}
row = lipgloss.JoinHorizontal(lipgloss.Top, banner, " ", selectorColumn, " ", spinner)
return row
}