addet some fixes and styling

This commit is contained in:
pika 2024-12-09 22:46:57 +01:00
parent 859c6d328e
commit cc92bc3e26
3 changed files with 127 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strings"
"time"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
@ -29,6 +30,7 @@ type model struct {
err error
width int
height int
clock time.Time
}
// Initial model setup
@ -44,13 +46,19 @@ func initialModel() model {
return model{
searchBar: searchBar,
results: results,
showSearch: true, // Start in search mode
showSearch: true,
clock: time.Now(),
width: 80, // Default width
height: 24, // Default height
}
}
// Init initializes the Bubble Tea program
func (m model) Init() tea.Cmd {
return textinput.Blink
return tea.Batch(
textinput.Blink,
tickCmd(),
)
}
// Update handles updates to the model based on user input
@ -112,6 +120,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.width = msg.Width
m.height = msg.Height
m.results.SetSize(msg.Width, msg.Height-3) // Leave space for search bar
case time.Time:
m.clock = msg
return m, tickCmd()
}
var cmd tea.Cmd
@ -127,6 +139,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m model) View() string {
var s strings.Builder
// Add clock to top-right corner with safety check for window width
clock := m.clock.Format("15:04:05 02-01-2006")
if m.width > len(clock) {
padding := strings.Repeat(" ", m.width-len(clock))
s.WriteString(padding + clock + "\n\n")
} else {
s.WriteString(clock + "\n\n")
}
// Always show search bar at the top
searchText := "Press '/' to search"
if m.showSearch {
@ -150,3 +171,9 @@ func Run() error {
p := tea.NewProgram(initialModel())
return p.Start()
}
func tickCmd() tea.Cmd {
return tea.Every(time.Second, func(t time.Time) tea.Msg {
return t
})
}