This commit updates the project's dependencies, including `charmbracelet/bubbles`, `charmbracelet/bubbletea`, and `charmbracelet/lipgloss`. The UI has been adjusted to utilize `lipgloss.Place` for centering the text input within the terminal window. It also now displays a "loading..." message until the window size is determined. The text input prompt has been removed to provide a cleaner interface.
70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/charmbracelet/bubbles/textinput"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
type model struct {
|
|
textInput textinput.Model
|
|
width int
|
|
height int
|
|
}
|
|
|
|
func initialModel() model {
|
|
ti := textinput.New()
|
|
ti.Placeholder = "Search"
|
|
ti.Width = 30
|
|
ti.CharLimit = 30
|
|
ti.Prompt = ""
|
|
ti.Focus()
|
|
return model{
|
|
textInput: ti,
|
|
}
|
|
}
|
|
|
|
func (m model) Init() tea.Cmd {
|
|
return textinput.Blink
|
|
}
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
var cmd tea.Cmd
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
switch msg.String() {
|
|
case "q", "ctrl+c":
|
|
return m, tea.Quit
|
|
}
|
|
case tea.WindowSizeMsg:
|
|
m.width = msg.Width
|
|
m.height = msg.Height
|
|
}
|
|
m.textInput, cmd = m.textInput.Update(msg)
|
|
return m, cmd
|
|
}
|
|
|
|
func (m model) View() string {
|
|
if m.width == 0 {
|
|
return "loading..."
|
|
}
|
|
return lipgloss.Place(
|
|
m.width,
|
|
m.height,
|
|
lipgloss.Center,
|
|
0,
|
|
lipgloss.NewStyle().BorderStyle(lipgloss.ThickBorder()).Padding(0, 1).Render(m.textInput.View()),
|
|
)
|
|
}
|
|
|
|
func main() {
|
|
p := tea.NewProgram(initialModel(), tea.WithAltScreen())
|
|
if _, err := p.Run(); err != nil {
|
|
fmt.Println("Error:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|