2022-12-31 19:03:53 -05:00
|
|
|
package header
|
|
|
|
|
|
|
|
import (
|
2023-01-04 21:43:11 -05:00
|
|
|
"fmt"
|
|
|
|
|
2023-01-06 19:46:41 -05:00
|
|
|
"github.com/mrusme/neonmodem/ui/ctx"
|
2022-12-31 19:03:53 -05:00
|
|
|
|
|
|
|
"github.com/charmbracelet/bubbles/spinner"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
highlight = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}
|
2023-01-06 19:01:38 -05:00
|
|
|
|
2023-01-08 16:37:32 -05:00
|
|
|
overdrive = lipgloss.NewStyle().Foreground(lipgloss.Color("#f119a0"))
|
|
|
|
|
|
|
|
banner = lipgloss.NewStyle().Foreground(lipgloss.Color("#3c4f92")).Render(" ________ _____ _____ ________") + "\n" +
|
|
|
|
lipgloss.NewStyle().Foreground(lipgloss.Color("#bff1fe")).Render("| | | __| | | | ") + overdrive.Render("O") + "\n" +
|
|
|
|
lipgloss.NewStyle().Foreground(lipgloss.Color("#1b0d35")).Render("| | | | __| | | | | | ") + overdrive.Render("V") + "\n" +
|
|
|
|
lipgloss.NewStyle().Foreground(lipgloss.Color("#7c8eb5")).Render("|___|____|_____|_____|___|____| ") + overdrive.Render("R") + "\n" +
|
|
|
|
lipgloss.NewStyle().Foreground(lipgloss.Color("#2d3588")).Render("| | | \\| __| | ") + overdrive.Render("D") + "\n" +
|
|
|
|
lipgloss.NewStyle().Foreground(lipgloss.Color("#b4effe")).Render("| | | | | | | | __| | | | ") + overdrive.Render("R") + "\n" +
|
|
|
|
lipgloss.NewStyle().Foreground(lipgloss.Color("#28254c")).Render("|_|_|_|_____|____/|_____|_|_|_| ") + overdrive.Render("V")
|
2022-12-31 19:03:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2023-06-24 20:57:20 -04:00
|
|
|
m.spinner.Style = lipgloss.NewStyle().Foreground(
|
|
|
|
m.ctx.Theme.Header.Spinner.GetForeground())
|
2022-12-31 19:03:53 -05:00
|
|
|
|
|
|
|
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)
|
2023-01-01 20:13:02 -05:00
|
|
|
} else {
|
|
|
|
return m, nil
|
2022-12-31 19:03:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2023-01-01 01:59:10 -05:00
|
|
|
var row string
|
2023-01-04 19:13:04 -05:00
|
|
|
var spinner string = ""
|
2022-12-31 19:03:53 -05:00
|
|
|
|
2023-01-05 20:47:20 -05:00
|
|
|
selectorWidth := 40
|
|
|
|
selectorTextLen := selectorWidth - 7
|
2023-01-04 19:13:04 -05:00
|
|
|
|
2023-01-04 21:43:11 -05:00
|
|
|
curSysIdx := m.ctx.GetCurrentSystem()
|
|
|
|
var currentSystem string = "All"
|
|
|
|
if curSysIdx >= 0 {
|
2023-01-04 23:59:59 -05:00
|
|
|
currentSystem = (*m.ctx.Systems[curSysIdx]).Title()
|
2023-01-05 20:47:20 -05:00
|
|
|
if len(currentSystem) > selectorTextLen {
|
|
|
|
currentSystem = currentSystem[0:selectorTextLen]
|
|
|
|
}
|
2023-01-04 21:43:11 -05:00
|
|
|
}
|
|
|
|
|
2023-01-05 11:43:52 -05:00
|
|
|
curForum := m.ctx.GetCurrentForum()
|
|
|
|
var currentForum string = "All"
|
|
|
|
if curForum.ID != "" {
|
|
|
|
currentForum = curForum.Title()
|
2023-01-05 20:47:20 -05:00
|
|
|
if len(currentForum) > selectorTextLen {
|
|
|
|
currentForum = currentForum[0:selectorTextLen]
|
|
|
|
}
|
2023-01-05 11:43:52 -05:00
|
|
|
}
|
|
|
|
|
2023-01-07 00:11:44 -05:00
|
|
|
systemSelector := m.ctx.Theme.Header.Selector.
|
|
|
|
Width(selectorWidth).Render(fmt.Sprintf("⏷ %s", currentSystem))
|
|
|
|
forumSelector := m.ctx.Theme.Header.Selector.
|
|
|
|
Width(selectorWidth).Render(fmt.Sprintf("⏷ %s", currentForum))
|
2023-01-04 19:13:04 -05:00
|
|
|
|
|
|
|
selectorColumn := lipgloss.JoinVertical(lipgloss.Center,
|
|
|
|
lipgloss.JoinHorizontal(lipgloss.Bottom, "System: \n "+
|
2023-01-07 00:11:44 -05:00
|
|
|
lipgloss.NewStyle().Foreground(
|
|
|
|
m.ctx.Theme.DialogBox.Bottombar.GetForeground(),
|
|
|
|
).Render("C-e"),
|
2023-01-04 19:13:04 -05:00
|
|
|
systemSelector),
|
|
|
|
lipgloss.JoinHorizontal(lipgloss.Bottom, "Forum: \n "+
|
2023-01-07 00:11:44 -05:00
|
|
|
lipgloss.NewStyle().Foreground(
|
|
|
|
m.ctx.Theme.DialogBox.Bottombar.GetForeground(),
|
|
|
|
).Render("C-t"),
|
2023-01-04 19:13:04 -05:00
|
|
|
forumSelector),
|
|
|
|
)
|
|
|
|
|
|
|
|
if m.ctx.Loading == true {
|
|
|
|
spinner = m.spinner.View()
|
2022-12-31 19:03:53 -05:00
|
|
|
}
|
|
|
|
|
2023-06-23 17:36:57 -04:00
|
|
|
if !m.ctx.Config.RenderBanner{
|
|
|
|
banner = ""
|
|
|
|
}
|
|
|
|
|
2023-01-08 16:37:32 -05:00
|
|
|
row = lipgloss.JoinHorizontal(lipgloss.Bottom,
|
2023-01-07 00:11:44 -05:00
|
|
|
banner,
|
|
|
|
" ",
|
|
|
|
selectorColumn,
|
|
|
|
" ",
|
|
|
|
spinner,
|
|
|
|
)
|
2023-01-04 19:13:04 -05:00
|
|
|
|
2023-01-01 01:59:10 -05:00
|
|
|
return row
|
2022-12-31 19:03:53 -05:00
|
|
|
}
|