From 5c41cd4038cbec108b5cb8ceefad56319b67494b Mon Sep 17 00:00:00 2001 From: Slug-Boi Date: Thu, 10 Apr 2025 22:31:34 +0200 Subject: [PATCH] refactor: edit existing tui elements to add new gh add tui component --- src/cmd/tui/tui_author.go | 27 +++++++++++++++++++++++++++ src/cmd/tui/tui_list.go | 9 +++++++++ 2 files changed, 36 insertions(+) diff --git a/src/cmd/tui/tui_author.go b/src/cmd/tui/tui_author.go index 1d16075..0848e07 100644 --- a/src/cmd/tui/tui_author.go +++ b/src/cmd/tui/tui_author.go @@ -137,6 +137,33 @@ func intitialErrorModel() *errorModel { } } +func createGHTempAuthorModel(old_m *model, user utils.User) model_ca { + parent_m = old_m + m := model_ca{ + inputs: make([]textinput.Model, 2), + errorModel: intitialErrorModel(), + } + var t textinput.Model + for i := range m.inputs { + t = textinput.New() + t.Cursor.Style = cursorStyle + switch i { + case 0: + t.Placeholder = "Username (e.g. JohnDoe-gh)" + t.SetValue(user.Username) + t.Focus() + t.PromptStyle = focusedStyle + t.TextStyle = focusedStyle + case 1: + t.Placeholder = "Email (e.g. JohnDoe@domain.do)" + t.SetValue(user.Email) + } + m.inputs[i] = t + } + tempAuthorToggle = true + return m +} + func createGHAuthorModel(old_m *model, user utils.User) model_ca { parent_m = old_m diff --git a/src/cmd/tui/tui_list.go b/src/cmd/tui/tui_list.go index 29884ff..3247622 100644 --- a/src/cmd/tui/tui_list.go +++ b/src/cmd/tui/tui_list.go @@ -47,6 +47,7 @@ type listKeyMap struct { createAuthor key.Binding deleteAuthor key.Binding tempAdd key.Binding + ghAdd key.Binding } func newListKeyMap() *listKeyMap { @@ -79,6 +80,10 @@ func newListKeyMap() *listKeyMap { key.WithKeys("T"), key.WithHelp("T", "Add temporary author"), ), + ghAdd: key.NewBinding( + key.WithKeys("c"), + key.WithHelp("c", "Add GitHub author"), + ), } } @@ -180,6 +185,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } // Handle keys from keyList (help menu) switch { + case key.Matches(msg, m.keys.ghAdd): + sub_model = NewGitHubUserForm(&m) + return m, tea.ClearScreen + case key.Matches(msg, m.keys.negation): i, ok := m.list.SelectedItem().(item) if ok {