Update dependencies and adjust UI
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.
This commit is contained in:
18
main.go
18
main.go
@@ -6,10 +6,13 @@ import (
|
||||
|
||||
"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 {
|
||||
@@ -17,6 +20,7 @@ func initialModel() model {
|
||||
ti.Placeholder = "Search"
|
||||
ti.Width = 30
|
||||
ti.CharLimit = 30
|
||||
ti.Prompt = ""
|
||||
ti.Focus()
|
||||
return model{
|
||||
textInput: ti,
|
||||
@@ -35,13 +39,25 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
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 {
|
||||
return fmt.Sprint(m.textInput.View())
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user