Compare commits

..

3 Commits

Author SHA1 Message Date
vaibhav
9dc394ad5c Add sidebar and search box layout
Introduce a `sidebarContent` field to the `model` and update the `View`
function to render a sidebar alongside the text input, creating a basic
two-pane layout.
2026-01-14 11:44:24 +05:30
vaibhav
7fa9e9b1bd 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.
2026-01-14 11:43:17 +05:30
vaibhav
761961b452 Refactor: Add text input functionality
Replaces the counter with a text input field for user interaction. This
change leverages the `textinput` bubble to provide a more interactive
experience within the TUI. The `go.mod` and `go.sum` files have been
updated to include the necessary dependency.
2026-01-14 04:13:52 +05:30
4 changed files with 55 additions and 18 deletions

10
go.mod
View File

@@ -3,11 +3,15 @@ module github.com/vvaibhavv11/player
go 1.25.0
require (
github.com/charmbracelet/bubbles v0.21.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/lipgloss v1.1.0
)
require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/bubbles v0.21.0 // indirect
github.com/charmbracelet/bubbletea v1.3.10 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/lipgloss v1.1.0 // indirect
github.com/charmbracelet/x/ansi v0.10.1 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect

4
go.sum
View File

@@ -1,3 +1,5 @@
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
@@ -35,6 +37,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=

59
main.go
View File

@@ -4,49 +4,78 @@ import (
"fmt"
"os"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type model struct {
counter int
textInput textinput.Model
width int
height int
sidebarContent string
}
func initialModel() model {
return model{counter: 0}
ti := textinput.New()
ti.Placeholder = "Search"
ti.Width = 30
ti.CharLimit = 30
ti.Prompt = ""
ti.Focus()
return model{
textInput: ti,
sidebarContent: "Library\n\nPlaylist 1\nPlaylist 2\nFavorites",
}
}
func (m model) Init() tea.Cmd {
return nil
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 "+":
m.counter++
case "-":
m.counter--
}
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
}
return m, nil
m.textInput, cmd = m.textInput.Update(msg)
return m, cmd
}
func (m model) View() string {
return fmt.Sprintf(
"Counter: %d\n\nPress + / - to change\nPress q to quit\n",
m.counter,
if m.width == 0 {
return "loading..."
}
// Create search box
searchBox := lipgloss.NewStyle().BorderStyle(lipgloss.ThickBorder()).Padding(0, 1).Render(m.textInput.View())
// Create sidebar
sidebar := lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).Padding(1, 2).Render(m.sidebarContent)
// Combine search and sidebar vertically
content := lipgloss.JoinVertical(lipgloss.Left, searchBox, "\n", sidebar)
return lipgloss.Place(
m.width,
m.height,
lipgloss.Center,
lipgloss.Center,
content,
)
}
func main() {
p := tea.NewProgram(initialModel())
if err := p.Start(); err != nil {
p := tea.NewProgram(initialModel(), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
}

BIN
player Executable file

Binary file not shown.