Skip to content

Commit

Permalink
Changed list to be a simple one.
Browse files Browse the repository at this point in the history
The other list showed redundant information.
  • Loading branch information
ariasmn committed Jul 18, 2022
1 parent 79a8c00 commit 6107c36
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
31 changes: 31 additions & 0 deletions internal/tui/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tui

import (
"fmt"
"io"

"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
)

type itemDelegate struct{}

func (d itemDelegate) Height() int { return 1 }
func (d itemDelegate) Spacing() int { return 0 }
func (d itemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
user, ok := listItem.(item)
if !ok {
return
}

line := user.Details.Username

if index == m.Index() {
line = selectedItemStyle.Render("> " + line)
} else {
line = itemStyle.Render(line)
}

fmt.Fprint(w, line)
}
6 changes: 1 addition & 5 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package tui

import (
"fmt"

"github.com/ariasmn/ugm/userparser"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/viewport"
)

type item userparser.User

func (i item) Title() string { return i.Details.Username }
func (i item) Description() string { return fmt.Sprintf("UID: %s, GID: %s", i.Details.Uid, i.Details.Gid) }
func (i item) FilterValue() string { return i.Details.Username }

type BubbleUser struct {
Expand All @@ -21,7 +17,7 @@ type BubbleUser struct {

func InitialModel() BubbleUser {
items := userToItem(userparser.GetUsers())
l := list.New(items, list.NewDefaultDelegate(), 0, 0)
l := list.New(items, itemDelegate{}, 0, 0)
l.Title = "Users"
l.SetShowHelp(false)

Expand Down
5 changes: 5 additions & 0 deletions internal/tui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ var (
Border(lipgloss.RoundedBorder(), false, true, false, false)
listColorStyle = lipgloss.NewStyle().
Background(lipgloss.Color("#3d719c"))
itemStyle = lipgloss.NewStyle().
PaddingLeft(4)
selectedItemStyle = lipgloss.NewStyle().
PaddingLeft(2).
Foreground(lipgloss.Color("#569cd6"))
detailStyle = lipgloss.NewStyle().
PaddingTop(2)
dividerStyle = lipgloss.NewStyle().
Expand Down

0 comments on commit 6107c36

Please sign in to comment.