mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 20:55:47 +00:00
feat: finish add and remove author bindings and tui elements
This commit is contained in:
@@ -5,6 +5,7 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"main/src_code/go_src/cmd/utils"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -179,7 +180,7 @@ func (m model_ca) View() string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func Entry_CA() {
|
||||
func Entry_CA() string{
|
||||
m, err := tea.NewProgram(initialModel()).Run()
|
||||
if err != nil {
|
||||
fmt.Printf("could not start program: %s\n", err)
|
||||
@@ -201,6 +202,7 @@ func Entry_CA() {
|
||||
defer f.Close()
|
||||
|
||||
sb := strings.Builder{}
|
||||
sb.WriteRune('\n')
|
||||
|
||||
sb.WriteString(fmt.Sprintf("%s|%s|%s|%s",
|
||||
m.(model_ca).inputs[0].Value(),
|
||||
@@ -216,11 +218,13 @@ func Entry_CA() {
|
||||
sb.WriteString(fmt.Sprintf(";;%s", m.(model_ca).inputs[4].Value()))
|
||||
}
|
||||
|
||||
sb.WriteRune('\n')
|
||||
//sb.WriteRune('\n')
|
||||
|
||||
if _, err = f.WriteString(sb.String()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
utils.Define_users(utils.Find_authorfile())
|
||||
return m.(model_ca).inputs[0].Value()
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
@@ -33,12 +33,15 @@ var selected = map[string]item{}
|
||||
|
||||
var negation = false
|
||||
|
||||
var dupProtect = map[string]string{}
|
||||
|
||||
type listKeyMap struct {
|
||||
selectAll key.Binding
|
||||
negation key.Binding
|
||||
groupSelect key.Binding
|
||||
selectOne key.Binding
|
||||
createAuthor key.Binding
|
||||
deleteAuthor key.Binding
|
||||
}
|
||||
|
||||
func newListKeyMap() *listKeyMap {
|
||||
@@ -63,6 +66,10 @@ func newListKeyMap() *listKeyMap {
|
||||
key.WithKeys("C"),
|
||||
key.WithHelp("C", "Create new author"),
|
||||
),
|
||||
deleteAuthor: key.NewBinding(
|
||||
key.WithKeys("D"),
|
||||
key.WithHelp("D", "Delete author"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +181,19 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// group code goes here
|
||||
|
||||
case key.Matches(msg, m.keys.createAuthor):
|
||||
Entry_CA()
|
||||
author := Entry_CA()
|
||||
if author != "" {
|
||||
item_str := utils.Users[author].Username + " - " + utils.Users[author].Email
|
||||
dupProtect[item_str] = author
|
||||
m.list.InsertItem(len(m.list.Items())+1,item(item_str))
|
||||
}
|
||||
return m, tea.ClearScreen
|
||||
case key.Matches(msg, m.keys.deleteAuthor):
|
||||
author_str := string(m.list.SelectedItem().(item))
|
||||
author := dupProtect[author_str]
|
||||
utils.DeleteOneAuthor(author)
|
||||
delete(dupProtect, author_str)
|
||||
m.list.RemoveItem(m.list.Index())
|
||||
return m, tea.ClearScreen
|
||||
}
|
||||
// extra key options
|
||||
@@ -206,7 +225,6 @@ func (m model) View() string {
|
||||
//TODO: pass list in as a param to allow for group selection using same template
|
||||
func Entry() []string {
|
||||
items := []list.Item{}
|
||||
dupProtect := map[string]string{}
|
||||
|
||||
listKeys := newListKeyMap()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user