mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
feat: add temp add command
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/inancgumus/screen"
|
||||
)
|
||||
|
||||
const listHeight = 14
|
||||
@@ -32,6 +33,7 @@ type item string
|
||||
var selected = map[string]item{}
|
||||
|
||||
var negation = false
|
||||
var ignore = false
|
||||
|
||||
var dupProtect = map[string]string{}
|
||||
|
||||
@@ -42,6 +44,7 @@ type listKeyMap struct {
|
||||
selectOne key.Binding
|
||||
createAuthor key.Binding
|
||||
deleteAuthor key.Binding
|
||||
tempAdd key.Binding
|
||||
}
|
||||
|
||||
func newListKeyMap() *listKeyMap {
|
||||
@@ -70,10 +73,13 @@ func newListKeyMap() *listKeyMap {
|
||||
key.WithKeys("D"),
|
||||
key.WithHelp("D", "Delete author"),
|
||||
),
|
||||
tempAdd: key.NewBinding(
|
||||
key.WithKeys("T"),
|
||||
key.WithHelp("T", "Add temporary author"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: Try and add filtering later down the line
|
||||
func (i item) FilterValue() string { return string(i) }
|
||||
|
||||
@@ -88,7 +94,6 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
str := fmt.Sprintf("%d. %s", index+1, i)
|
||||
|
||||
//TODO: add negation style where all items are flipped in selection
|
||||
@@ -114,7 +119,6 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fmt.Fprint(w, fn(str))
|
||||
}
|
||||
|
||||
@@ -144,7 +148,6 @@ func toggleNegation() {
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
m.list.SetWidth(msg.Width)
|
||||
@@ -180,6 +183,18 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case key.Matches(msg, m.keys.groupSelect):
|
||||
// group code goes here
|
||||
|
||||
case key.Matches(msg, m.keys.tempAdd):
|
||||
screen.Clear()
|
||||
screen.MoveTopLeft()
|
||||
tempAuthr := Entry_TA()
|
||||
if tempAuthr != "" {
|
||||
split := strings.Split(tempAuthr, ":")
|
||||
item_str := split[0] + " - " + split[1]
|
||||
dupProtect[item_str] = tempAuthr
|
||||
m.list.InsertItem(len(m.list.Items())+1, item(item_str))
|
||||
}
|
||||
return m, tea.ClearScreen
|
||||
|
||||
case key.Matches(msg, m.keys.createAuthor):
|
||||
author := Entry_CA()
|
||||
if author != "" {
|
||||
@@ -279,7 +294,9 @@ func Entry() []string {
|
||||
// Assert the final tea.Model to our local model and print the choice.
|
||||
|
||||
output := []string{}
|
||||
|
||||
if len(selected) == 0 {
|
||||
os.Exit(0)
|
||||
}
|
||||
for i := range selected {
|
||||
short := dupProtect[i]
|
||||
if negation {
|
||||
|
||||
Reference in New Issue
Block a user