2023-12-22 15:50:42 +01:00
|
|
|
package tui
|
|
|
|
|
|
|
|
import (
|
2023-12-23 12:08:58 +01:00
|
|
|
"ewintr.nl/emdb/client"
|
2023-12-24 11:03:32 +01:00
|
|
|
"github.com/charmbracelet/bubbles/viewport"
|
2023-12-22 15:50:42 +01:00
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
2023-12-23 12:08:58 +01:00
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
|
|
"github.com/muesli/termenv"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
colorNormalForeground = lipgloss.ANSIColor(termenv.ANSIWhite)
|
|
|
|
colorHighLightForeGround = lipgloss.ANSIColor(termenv.ANSIBrightWhite)
|
|
|
|
windowStyle = lipgloss.NewStyle().
|
|
|
|
BorderForeground(colorHighLightForeGround).
|
|
|
|
Foreground(colorNormalForeground).
|
|
|
|
Border(lipgloss.NormalBorder(), true)
|
2023-12-24 13:54:02 +01:00
|
|
|
logLineCount = 10
|
2023-12-22 15:50:42 +01:00
|
|
|
)
|
|
|
|
|
2023-12-23 18:43:38 +01:00
|
|
|
type Logger struct {
|
|
|
|
p *tea.Program
|
|
|
|
Lines []string
|
2023-12-23 12:08:58 +01:00
|
|
|
}
|
|
|
|
|
2023-12-23 18:43:38 +01:00
|
|
|
func NewLogger() *Logger {
|
|
|
|
return &Logger{
|
|
|
|
Lines: make([]string, 0),
|
2023-12-22 15:50:42 +01:00
|
|
|
}
|
2023-12-23 12:08:58 +01:00
|
|
|
}
|
|
|
|
|
2023-12-24 13:33:15 +01:00
|
|
|
func (l *Logger) SetProgram(p *tea.Program) { l.p = p }
|
|
|
|
func (l *Logger) Log(s string) { l.Lines = append(l.Lines, s) }
|
2023-12-23 12:08:58 +01:00
|
|
|
|
2023-12-25 09:21:00 +01:00
|
|
|
type NewMovie Movie
|
2023-12-23 12:08:58 +01:00
|
|
|
|
2023-12-27 08:25:09 +01:00
|
|
|
type NextTabSelected struct{}
|
|
|
|
|
|
|
|
func SelectNextTab() tea.Cmd {
|
|
|
|
return func() tea.Msg {
|
|
|
|
return NextTabSelected{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PrevTabSelected struct{}
|
|
|
|
|
|
|
|
func SelectPrevTab() tea.Cmd {
|
|
|
|
return func() tea.Msg {
|
|
|
|
return PrevTabSelected{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-24 11:03:32 +01:00
|
|
|
func New(emdb *client.EMDB, tmdb *client.TMDB, logger *Logger) (*tea.Program, error) {
|
|
|
|
logViewport := viewport.New(0, 0)
|
|
|
|
logViewport.KeyMap = viewport.KeyMap{}
|
2023-12-23 18:43:38 +01:00
|
|
|
|
2023-12-24 11:03:32 +01:00
|
|
|
m, _ := NewBaseModel(emdb, tmdb, logger)
|
2023-12-23 18:43:38 +01:00
|
|
|
p := tea.NewProgram(m, tea.WithAltScreen())
|
|
|
|
|
|
|
|
return p, nil
|
2023-12-22 15:50:42 +01:00
|
|
|
}
|