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"
|
"github.com/charmbracelet/bubbles/list"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
"github.com/inancgumus/screen"
|
||||||
)
|
)
|
||||||
|
|
||||||
const listHeight = 14
|
const listHeight = 14
|
||||||
@@ -32,6 +33,7 @@ type item string
|
|||||||
var selected = map[string]item{}
|
var selected = map[string]item{}
|
||||||
|
|
||||||
var negation = false
|
var negation = false
|
||||||
|
var ignore = false
|
||||||
|
|
||||||
var dupProtect = map[string]string{}
|
var dupProtect = map[string]string{}
|
||||||
|
|
||||||
@@ -42,6 +44,7 @@ type listKeyMap struct {
|
|||||||
selectOne key.Binding
|
selectOne key.Binding
|
||||||
createAuthor key.Binding
|
createAuthor key.Binding
|
||||||
deleteAuthor key.Binding
|
deleteAuthor key.Binding
|
||||||
|
tempAdd key.Binding
|
||||||
}
|
}
|
||||||
|
|
||||||
func newListKeyMap() *listKeyMap {
|
func newListKeyMap() *listKeyMap {
|
||||||
@@ -70,11 +73,14 @@ func newListKeyMap() *listKeyMap {
|
|||||||
key.WithKeys("D"),
|
key.WithKeys("D"),
|
||||||
key.WithHelp("D", "Delete author"),
|
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
|
||||||
//TODO: Try and add filtering later down the line
|
|
||||||
func (i item) FilterValue() string { return string(i) }
|
func (i item) FilterValue() string { return string(i) }
|
||||||
|
|
||||||
type itemDelegate struct{}
|
type itemDelegate struct{}
|
||||||
@@ -88,7 +94,6 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
str := fmt.Sprintf("%d. %s", index+1, i)
|
str := fmt.Sprintf("%d. %s", index+1, i)
|
||||||
|
|
||||||
//TODO: add negation style where all items are flipped in selection
|
//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))
|
fmt.Fprint(w, fn(str))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +148,6 @@ func toggleNegation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.list.SetWidth(msg.Width)
|
m.list.SetWidth(msg.Width)
|
||||||
@@ -180,12 +183,24 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case key.Matches(msg, m.keys.groupSelect):
|
case key.Matches(msg, m.keys.groupSelect):
|
||||||
// group code goes here
|
// 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):
|
case key.Matches(msg, m.keys.createAuthor):
|
||||||
author := Entry_CA()
|
author := Entry_CA()
|
||||||
if author != "" {
|
if author != "" {
|
||||||
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
|
||||||
m.list.InsertItem(len(m.list.Items())+1,item(item_str))
|
m.list.InsertItem(len(m.list.Items())+1, item(item_str))
|
||||||
}
|
}
|
||||||
return m, tea.ClearScreen
|
return m, tea.ClearScreen
|
||||||
case key.Matches(msg, m.keys.deleteAuthor):
|
case key.Matches(msg, m.keys.deleteAuthor):
|
||||||
@@ -222,7 +237,7 @@ func (m model) View() string {
|
|||||||
return "\n" + m.list.View()
|
return "\n" + m.list.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: pass list in as a param to allow for group selection using same template
|
// TODO: pass list in as a param to allow for group selection using same template
|
||||||
func Entry() []string {
|
func Entry() []string {
|
||||||
items := []list.Item{}
|
items := []list.Item{}
|
||||||
|
|
||||||
@@ -279,7 +294,9 @@ func Entry() []string {
|
|||||||
// Assert the final tea.Model to our local model and print the choice.
|
// Assert the final tea.Model to our local model and print the choice.
|
||||||
|
|
||||||
output := []string{}
|
output := []string{}
|
||||||
|
if len(selected) == 0 {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
for i := range selected {
|
for i := range selected {
|
||||||
short := dupProtect[i]
|
short := dupProtect[i]
|
||||||
if negation {
|
if negation {
|
||||||
|
|||||||
Reference in New Issue
Block a user