feat: add color to Authors in list view based on where they were added from scope wise

This commit is contained in:
Slug-Boi
2026-04-28 11:29:47 +02:00
parent 5a2ca228c6
commit 0a55fe0c93
6 changed files with 115 additions and 61 deletions
+3 -3
View File
@@ -463,7 +463,7 @@ func (m *model_ca) AddAuthor() bool {
if parent_m != nil { if parent_m != nil {
item_str := utils.Users[author].Username + " - " + utils.Users[author].Email item_str := utils.Users[author].Username + " - " + utils.Users[author].Email
dupProtect[item_str] = author dupProtect[item_str] = author
parent_m.list.InsertItem(len(parent_m.list.Items())+1, item(item_str)) parent_m.list.InsertItem(len(parent_m.list.Items())+1, item{item_str, local_scope})
} }
return false return false
} }
@@ -474,8 +474,8 @@ func (m *model_ca) TempAddAuthor() bool {
if len(m.inputs) > 1 && m.inputs[0].Value() != "" && m.inputs[1].Value() != "" { if len(m.inputs) > 1 && m.inputs[0].Value() != "" && m.inputs[1].Value() != "" {
item_str := m.inputs[0].Value() + " - " + m.inputs[1].Value() item_str := m.inputs[0].Value() + " - " + m.inputs[1].Value()
dupProtect[item_str] = m.inputs[0].Value() + ":" + m.inputs[1].Value() dupProtect[item_str] = m.inputs[0].Value() + ":" + m.inputs[1].Value()
i := item(item_str) i := item{item_str, local_scope}
parent_m.list.InsertItem(len(parent_m.list.Items())+1, item(item_str)) parent_m.list.InsertItem(len(parent_m.list.Items())+1, item{item_str, local_scope})
selectToggle(i) selectToggle(i)
return false return false
+2 -2
View File
@@ -118,7 +118,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
if group != "" { if group != "" {
for _, sel := range selected { for _, sel := range selected {
delete(selected, string(sel)) delete(selected, string(sel.display))
} }
users := utils.Groups[group] users := utils.Groups[group]
//TODO: this may be able to be done in a more efficient way currently this would scale poorly //TODO: this may be able to be done in a more efficient way currently this would scale poorly
@@ -126,7 +126,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if _, ok := selected[k]; !ok { if _, ok := selected[k]; !ok {
for _, user := range users { for _, user := range users {
if user.Shortname == v || user.Longname == v { if user.Shortname == v || user.Longname == v {
selectToggle(item(k)) selectToggle(item{k,local_scope})
} }
} }
} }
+91 -40
View File
@@ -27,12 +27,16 @@ var (
paginationStyle = list.DefaultStyles().PaginationStyle.PaddingLeft(4) paginationStyle = list.DefaultStyles().PaginationStyle.PaddingLeft(4)
ActivePaginationDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "170", Dark: "170"}) ActivePaginationDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "170", Dark: "170"})
helpStyle = list.DefaultStyles().HelpStyle.PaddingLeft(4).PaddingBottom(1) helpStyle = list.DefaultStyles().HelpStyle.PaddingLeft(4).PaddingBottom(1)
git_scope_style = lipgloss.NewStyle().Foreground(lipgloss.Color("170")).Bold(true) git_scope_style = lipgloss.NewStyle().Foreground(lipgloss.Color("49")).Bold(true)
local_scope_style = lipgloss.NewStyle().Foreground(lipgloss.Color("49")).Bold(true) git_scope_author_style = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("49"))
local_scope_style = lipgloss.NewStyle().Foreground(lipgloss.Color("170")).Bold(true)
mixed_scope_style = lipgloss.NewStyle().Foreground(lipgloss.Color("178")).Bold(true) mixed_scope_style = lipgloss.NewStyle().Foreground(lipgloss.Color("178")).Bold(true)
) )
type item string type item struct {
display string
source int
}
var selected = map[string]item{} var selected = map[string]item{}
@@ -95,7 +99,7 @@ func newListKeyMap() *listKeyMap {
} }
} }
func (i item) FilterValue() string { return string(i) } func (i item) FilterValue() string { return string(i.display) }
type itemDelegate struct{} type itemDelegate struct{}
@@ -103,35 +107,71 @@ func (d itemDelegate) Height() int { return 1 }
func (d itemDelegate) Spacing() int { return 0 } func (d itemDelegate) Spacing() int { return 0 }
func (d itemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil } func (d itemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil }
func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) { func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
i, ok := listItem.(item) i, ok := listItem.(item)
if !ok { if !ok {
return return
} }
str := fmt.Sprintf("%d. %s", index+1, i) // Choose base style according to source
var baseStyle lipgloss.Style
switch i.source {
case git_scope:
baseStyle = git_scope_author_style
case local_scope:
baseStyle = itemStyle
case mixed_scope:
baseStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("178"))
default:
baseStyle = itemStyle
}
fn := itemStyle.Render str := fmt.Sprintf("%d. %s", index+1, i.display)
if _, ok := selected[string(i)]; ok {
fn = func(s ...string) string {
base := strings.Join(s, " ")
if negation {
base = base + " ^"
}
if index == m.Index() {
return selectedHighlightStyle.Render("> " + base + " [X]")
} else {
return highlightStyle.Render(base + " [X]")
}
}
} else {
if index == m.Index() {
fn = func(s ...string) string {
return selectedItemStyle.Render("> " + strings.Join(s, " "))
}
}
}
fmt.Fprint(w, fn(str)) // Helper to render with the base style (applied to the string)
fn := func(s string) string {
return baseStyle.Render(s)
}
// Selection and cursor highlights (override background/padding)
if _, ok := selected[i.display]; ok {
fn = func(s string) string {
var style lipgloss.Style
if index == m.Index() {
style = lipgloss.NewStyle().
PaddingLeft(2).
Background(lipgloss.Color("206")).
Foreground(lipgloss.Color("90"))
} else {
style = lipgloss.NewStyle().
PaddingLeft(4).
Background(lipgloss.Color("236")).
Inherit(baseStyle) // keeps the foreground from baseStyle
}
result := style.Render(s + " [X]")
if negation {
result += " ^"
}
if index == m.Index() {
result = "> " + result
}
return result
}
} else {
if index == m.Index() {
fn = func(s string) string {
style := lipgloss.NewStyle().
PaddingLeft(2).
Inherit(baseStyle)
return style.Render("> " + s)
}
} else {
fn = func(s string) string {
return baseStyle.PaddingLeft(4).Render(s)
}
}
}
fmt.Fprint(w, fn(str))
} }
const ( const (
@@ -153,11 +193,11 @@ func (m Model) Init() tea.Cmd {
} }
func selectToggle(i item) { func selectToggle(i item) {
if _, ok := selected[string(i)]; ok { if _, ok := selected[string(i.display)]; ok {
delete(selected, string(i)) delete(selected, string(i.display))
toggleNegation() toggleNegation()
} else { } else {
selected[string(i)] = i selected[string(i.display)] = i
} }
} }
@@ -241,7 +281,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.ClearScreen return m, tea.ClearScreen
case key.Matches(msg, m.keys.deleteAuthor): case key.Matches(msg, m.keys.deleteAuthor):
if deletion { if deletion {
author_str := string(m.list.SelectedItem().(item)) author_str := string(m.list.SelectedItem().(item).display)
author := dupProtect[author_str] author := dupProtect[author_str]
utils.DeleteOneAuthor(author) utils.DeleteOneAuthor(author)
delete(dupProtect, author_str) delete(dupProtect, author_str)
@@ -324,7 +364,7 @@ func generate_list(scope int) []list.Item {
if _, ok := local_dupProtect[str_user]; ok { if _, ok := local_dupProtect[str_user]; ok {
continue continue
} }
items = append(items, item(str_user)) items = append(items, item{str_user, git_scope})
local_dupProtect[str_user] = short local_dupProtect[str_user] = short
} }
case local_scope: case local_scope:
@@ -334,7 +374,7 @@ func generate_list(scope int) []list.Item {
if _, ok := dupProtect[str_user]; ok { if _, ok := dupProtect[str_user]; ok {
continue continue
} }
items = append(items, item(str_user)) items = append(items, item{str_user, local_scope})
dupProtect[str_user] = short dupProtect[str_user] = short
} }
case mixed_scope: case mixed_scope:
@@ -344,17 +384,28 @@ func generate_list(scope int) []list.Item {
if _, ok := local_dupProtect[str_user]; ok { if _, ok := local_dupProtect[str_user]; ok {
continue continue
} }
items = append(items, item(str_user)) if user.From_git {
items = append(items, item{str_user, git_scope})
} else {
items = append(items, item{str_user, local_scope})
}
local_dupProtect[str_user] = short local_dupProtect[str_user] = short
} }
local_dupProtect = map[string]string{} //TODO: Why was this here?????
// local_dupProtect = map[string]string{}
for short, user := range utils.Git_Users { for short, user := range utils.Git_Users {
// if items already contains the user, skip it // if items already contains the user, skip it
str_user := user.Username + " - " + user.Email str_user := user.Username + " - " + user.Email
if _, ok := local_dupProtect[str_user]; ok { if _, ok := local_dupProtect[str_user]; ok {
continue continue
} }
items = append(items, item(str_user))
if user.From_git {
items = append(items, item{str_user, git_scope})
} else {
items = append(items, item{str_user, local_scope})
}
local_dupProtect[str_user] = short local_dupProtect[str_user] = short
} }
} }
@@ -413,7 +464,7 @@ func listModel(scope ...int) Model {
items := generate_list(scope[0]) items := generate_list(scope[0])
sort.Slice(items, func(i, j int) bool { sort.Slice(items, func(i, j int) bool {
return items[i].(item) < items[j].(item) return items[i].(item).display < items[j].(item).display
}) })
const defaultWidth = 20 const defaultWidth = 20
+1 -1
View File
@@ -157,7 +157,7 @@ func TestEntryTA(t *testing.T) {
t.Errorf("Expected 3 inputs, got %d", len(m.list.Items())) t.Errorf("Expected 3 inputs, got %d", len(m.list.Items()))
} }
item := string(m.list.Items()[len(m.list.Items())-1].(item)) item := string(m.list.Items()[len(m.list.Items())-1].(item).display)
split := strings.Split(item, " - ") split := strings.Split(item, " - ")
if split[0] != "test" { if split[0] != "test" {
+1
View File
@@ -0,0 +1 @@
Test content
+11 -9
View File
@@ -12,11 +12,12 @@ import (
type User struct { type User struct {
Shortname string `json:"shortname"` Shortname string `json:"shortname"`
Longname string `json:"longname"` Longname string `json:"longname"`
Username string `json:"username"` Username string `json:"username"`
Email string `json:"email"` Email string `json:"email"`
Ex bool `json:"ex"` Ex bool `json:"ex"`
Groups []string `json:"groups"` Groups []string `json:"groups"`
From_git bool
} }
type Author struct { type Author struct {
@@ -34,14 +35,14 @@ var Git_Users = map[string]User{}
var Git_Groups = map[string][]User{} var Git_Groups = map[string][]User{}
func ContainsUser(users []User, user User) bool { func ContainsUser(users []User, user User) bool {
return slices.ContainsFunc(users, func(u User) bool { return slices.ContainsFunc(users, func(u User) bool {
return u.Shortname == user.Shortname && return u.Shortname == user.Shortname &&
u.Longname == user.Longname && u.Longname == user.Longname &&
u.Username == user.Username && u.Username == user.Username &&
u.Email == user.Email && u.Email == user.Email &&
u.Ex == user.Ex && u.Ex == user.Ex &&
slices.Equal(u.Groups, user.Groups) slices.Equal(u.Groups, user.Groups)
}) })
} }
func CheckUserFields(user User) bool { func CheckUserFields(user User) bool {
@@ -102,6 +103,7 @@ func Define_git_users() {
for _, usr := range git_authors { for _, usr := range git_authors {
if _, ok := Users[usr.Shortname]; !ok { if _, ok := Users[usr.Shortname]; !ok {
usr.From_git = true
Git_Users[usr.Shortname] = usr Git_Users[usr.Shortname] = usr
Git_Users[usr.Longname] = usr Git_Users[usr.Longname] = usr