Compare commits

...

4 Commits

Author SHA1 Message Date
vaibhav
0eadc7b502 Refactor sidebar component to use struct
This commit refactors the sidebar component to use a struct for better
organization and maintainability. The `data` and `sindex` fields are now
exported as `Data` and `Sindex` respectively, allowing for easier access
and modification. Additionally, the styling for the selected sidebar
item has been updated for improved visual clarity.
2026-01-18 04:02:17 +05:30
vaibhav
1f413157ef Add basic navigation to sidebar 2026-01-16 04:16:37 +05:30
vaibhav
b92b173815 Add sidebar component
Introduce a new `Sidebar` component to encapsulate sidebar logic and
rendering. This component utilizes Bubble Tea and Lipgloss for UI
elements. The main application now integrates this component for
displaying sidebar content.
2026-01-16 02:05:12 +05:30
vaibhav
00590c569c Remove unused player executable 2026-01-14 11:51:41 +05:30
4 changed files with 73 additions and 8 deletions

View File

@@ -0,0 +1 @@
package components

53
components/sidebar.go Normal file
View File

@@ -0,0 +1,53 @@
package components
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type Sidebar struct {
Data []string
Sindex int
}
func (s Sidebar) Init() tea.Cmd {
return nil
}
func (s *Sidebar) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch m := msg.(type) {
case tea.KeyMsg:
switch m.String() {
case "up":
if s.Sindex > 0 {
s.Sindex--
}
case "down":
if s.Sindex < len(s.Data)-1 {
s.Sindex++
}
}
}
return s, nil
}
func (s Sidebar) View() string {
var items []string
for i, item := range s.Data {
if i == s.Sindex {
items = append(items, lipgloss.
NewStyle().
Foreground(lipgloss.Color("#FFFFFF")).
Background(lipgloss.Color("#93BD57")).
Render(item))
} else {
items = append(items, item)
}
}
return lipgloss.
NewStyle().
BorderStyle(lipgloss.NormalBorder()).
Padding(1, 2).
Render(lipgloss.JoinVertical(lipgloss.Left, items...))
}

27
main.go
View File

@@ -7,13 +7,14 @@ import (
"github.com/charmbracelet/bubbles/textinput" "github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"github.com/vvaibhavv11/player/components"
) )
type model struct { type model struct {
textInput textinput.Model textInput textinput.Model
width int width int
height int height int
sidebarContent string sidebarContent components.Sidebar
} }
func initialModel() model { func initialModel() model {
@@ -23,9 +24,14 @@ func initialModel() model {
ti.CharLimit = 30 ti.CharLimit = 30
ti.Prompt = "" ti.Prompt = ""
ti.Focus() ti.Focus()
sidebarcon := components.Sidebar{
Data: []string{"Library", "Playlist1", "Playlist2", "Favorites"},
Sindex: 0,
}
return model{ return model{
textInput: ti, textInput: ti,
sidebarContent: "Library\n\nPlaylist 1\nPlaylist 2\nFavorites", sidebarContent: sidebarcon,
} }
} }
@@ -54,20 +60,25 @@ func (m model) View() string {
return "loading..." return "loading..."
} }
// Create search box searchBox := lipgloss.Place(
searchBox := lipgloss.NewStyle().BorderStyle(lipgloss.ThickBorder()).Padding(0, 1).Render(m.textInput.View()) m.width,
m.height/12,
lipgloss.Center,
lipgloss.Center,
lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).Padding(0, 1).Render(m.textInput.View()),
)
// Create sidebar // Create sidebar
sidebar := lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).Padding(1, 2).Render(m.sidebarContent) // sidebar := lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).Padding(1, 2).Render(m.sidebarContent)
// Combine search and sidebar vertically // Combine search and sidebar vertically
content := lipgloss.JoinVertical(lipgloss.Left, searchBox, "\n", sidebar) content := lipgloss.JoinVertical(lipgloss.Left, searchBox, "\n", m.sidebarContent.View())
return lipgloss.Place( return lipgloss.Place(
m.width, m.width,
m.height, m.height,
lipgloss.Center, 0,
lipgloss.Center, 0,
content, content,
) )
} }

BIN
player

Binary file not shown.