diff --git a/src/cmd/tui/tui_author.go b/src/cmd/tui/tui_author.go index 119ff6d..c4f39fc 100644 --- a/src/cmd/tui/tui_author.go +++ b/src/cmd/tui/tui_author.go @@ -52,13 +52,13 @@ func errorGetMissingFields(m model_ca) { if len(m.inputs) > 0 { for i := 0; i < inpLen; i++ { if m.inputs[i].Value() == "" { - m.errorModel.missing = append(m.errorModel.missing, "- "+strings.Split(m.inputs[i].Placeholder," (")[0]) + m.errorModel.missing = append(m.errorModel.missing, "- "+strings.Split(m.inputs[i].Placeholder, " (")[0]) } } } else { m.errorModel.missing = append(m.errorModel.missing, "GIGA ERROR NO INPUTS") } - + } func (e errorModel) View() string { @@ -68,38 +68,37 @@ func (e errorModel) View() string { sb.WriteString("\nMissing fields: \n") sb.WriteString(strings.Join(e.missing, "\n")) } - - // Create centered content - content := lipgloss.JoinVertical( - lipgloss.Left, // Changed from Center to Left for better alignment - sb.String(), + + // Create centered content + content := lipgloss.JoinVertical( + lipgloss.Left, // Changed from Center to Left for better alignment + sb.String(), "\n\n[enter/esc]", - - ) + ) - // Create the error box - errorBox := lipgloss.NewStyle(). - Border(lipgloss.RoundedBorder()). - BorderForeground(lipgloss.Color("9")). - Padding(1, 2). - Width(40). - Foreground(lipgloss.Color("9")). - Background(lipgloss.Color("0")). + // Create the error box + errorBox := lipgloss.NewStyle(). + Border(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("9")). + Padding(1, 2). + Width(40). + Foreground(lipgloss.Color("9")). + Background(lipgloss.Color("0")). Align(lipgloss.Center). - Render(content) + Render(content) - return lipgloss.NewStyle(). - Padding(1, 0). - Render(errorBox) + return lipgloss.NewStyle(). + Padding(1, 0). + Render(errorBox) } -var parent_m *model +var parent_m *Model -func createAuthorModel(old_m *model) model_ca { +func createAuthorModel(old_m *Model) model_ca { parent_m = old_m m := model_ca{ - inputs: make([]textinput.Model, 5), + inputs: make([]textinput.Model, 5), errorModel: intitialErrorModel(), } @@ -137,10 +136,10 @@ func intitialErrorModel() *errorModel { } } -func createGHTempAuthorModel(old_m *model, user utils.User) model_ca { +func createGHTempAuthorModel(old_m *Model, user utils.User) model_ca { parent_m = old_m m := model_ca{ - inputs: make([]textinput.Model, 2), + inputs: make([]textinput.Model, 2), errorModel: intitialErrorModel(), } var t textinput.Model @@ -164,11 +163,11 @@ func createGHTempAuthorModel(old_m *model, user utils.User) model_ca { return m } -func createGHAuthorModel(old_m *model, user utils.User) model_ca { +func createGHAuthorModel(old_m *Model, user utils.User) model_ca { parent_m = old_m m := model_ca{ - inputs: make([]textinput.Model, 5), + inputs: make([]textinput.Model, 5), errorModel: intitialErrorModel(), } @@ -195,7 +194,7 @@ func createGHAuthorModel(old_m *model, user utils.User) model_ca { t.SetValue("") case 4: t.Placeholder = "Group tags (e.g. gr1|gr2)" - t.SetValue(strings.Join(user.Groups, "|")) + t.SetValue(strings.Join(user.Groups, "|")) } m.inputs[i] = t @@ -205,7 +204,7 @@ func createGHAuthorModel(old_m *model, user utils.User) model_ca { } func EntryGHAuthorModel(user utils.User) { - model := createGHAuthorModel(&model{}, user) + model := createGHAuthorModel(&Model{}, user) print(model.inputs[0].Value()) @@ -215,12 +214,11 @@ func EntryGHAuthorModel(user utils.User) { } } - -func tempAuthorModel(old_m *model) model_ca { +func tempAuthorModel(old_m *Model) model_ca { parent_m = old_m m := model_ca{ - inputs: make([]textinput.Model, 2), + inputs: make([]textinput.Model, 2), errorModel: intitialErrorModel(), } @@ -270,7 +268,7 @@ func updateErrorPopup(m model_ca, msg tea.Msg) (tea.Model, tea.Cmd) { func (m model_ca) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.errorModel.visible { return updateErrorPopup(m, msg) - } + } switch msg := msg.(type) { case tea.KeyMsg: @@ -297,8 +295,8 @@ func (m model_ca) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } if parent_m != nil { - return model{list: parent_m.list}, tea.ClearScreen - } else { + return Model{list: parent_m.list}, tea.ClearScreen + } else { m.quitting = true return m, tea.Quit } @@ -317,7 +315,7 @@ func (m model_ca) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } if parent_m.keys != nil { tempAuthorToggle = false - return model{list: parent_m.list}, tea.ClearScreen + return Model{list: parent_m.list}, tea.ClearScreen } else { m.quitting = true tempAuthorToggle = false @@ -440,7 +438,7 @@ func (m *model_ca) AddAuthor() bool { m.inputs[1].Value() != "" && m.inputs[2].Value() != "" && m.inputs[3].Value() != "" { - + var groups []string if m.inputs[4].Value() == "" { groups = []string{} @@ -455,7 +453,7 @@ func (m *model_ca) AddAuthor() bool { Username: m.inputs[2].Value(), Email: m.inputs[3].Value(), Ex: m.exclude, - Groups: groups, + Groups: groups, } utils.CreateAuthor(usr) @@ -468,7 +466,7 @@ func (m *model_ca) AddAuthor() bool { parent_m.list.InsertItem(len(parent_m.list.Items())+1, item(item_str)) } return false - } + } return true } @@ -480,7 +478,7 @@ func (m *model_ca) TempAddAuthor() bool { parent_m.list.InsertItem(len(parent_m.list.Items())+1, item(item_str)) selectToggle(i) - return false + return false } return true } diff --git a/src/cmd/tui/tui_github.go b/src/cmd/tui/tui_github.go index eadea72..7a206f3 100644 --- a/src/cmd/tui/tui_github.go +++ b/src/cmd/tui/tui_github.go @@ -12,30 +12,29 @@ import ( // Styles var ( - errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("9")) - toggleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("99")) + errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("9")) + toggleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("99")) activeToggleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) ) type GitHubUserModel struct { - inputs []textinput.Model - focusIndex int - submitted bool - showError bool - errorMsg string + inputs []textinput.Model + focusIndex int + submitted bool + showError bool + errorMsg string tempAuthShow bool - tempAuth bool + tempAuth bool } -func NewGitHubUserForm(old_m *model) GitHubUserModel { +func NewGitHubUserForm(old_m *Model) GitHubUserModel { parent_m = old_m - + m := GitHubUserModel{ inputs: make([]textinput.Model, 2), tempAuthShow: func() bool { return old_m != nil }(), - } // GitHub Username (required) @@ -70,7 +69,7 @@ func (m GitHubUserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return nil, nil } return m, tea.Quit - case "ctrl+t": // Toggle temp mode + case "ctrl+t": // Toggle temp mode if m.tempAuthShow { m.tempAuth = !m.tempAuth return m, nil @@ -91,22 +90,21 @@ func (m GitHubUserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { user.Email = m.inputs[1].Value() } if m.tempAuth { - return createGHTempAuthorModel(parent_m,user), tea.ClearScreen + return createGHTempAuthorModel(parent_m, user), tea.ClearScreen } - return createGHAuthorModel(parent_m,user), tea.ClearScreen - + return createGHAuthorModel(parent_m, user), tea.ClearScreen + } else if s == "enter" && m.focusIndex == len(m.inputs) && m.tempAuthShow { //toggle temp mode m.tempAuth = !m.tempAuth return m, nil } - // Cycle through inputs if s == "up" || s == "shift+tab" { m.focusIndex-- - } else { - m.focusIndex++ + } else { + m.focusIndex++ } inpNum := len(m.inputs) @@ -178,14 +176,14 @@ func (m GitHubUserModel) View() string { if m.tempAuth { toggleText = "[X]" } - + toggleBtn := fmt.Sprintf("[ TempAuthor ] %s ", toggleText) - - if m.focusIndex == len(m.inputs) { // When toggle is focused + + if m.focusIndex == len(m.inputs) { // When toggle is focused b.WriteString("\n" + focusedStyle.Render(toggleBtn)) - } else { - b.WriteString("\n" + blurredStyle.Render(toggleBtn)) - } + } else { + b.WriteString("\n" + blurredStyle.Render(toggleBtn)) + } } // Submit button @@ -223,4 +221,4 @@ func RunForm() (string, string, error) { } return "", "", nil -} \ No newline at end of file +} diff --git a/src/cmd/tui/tui_test.go b/src/cmd/tui/tui_test.go index c5f3950..130b105 100644 --- a/src/cmd/tui/tui_test.go +++ b/src/cmd/tui/tui_test.go @@ -148,7 +148,7 @@ func TestEntryTA(t *testing.T) { keyPress(tm, "esc") fm := tm.FinalModel(t) - m, ok := fm.(model) + m, ok := fm.(Model) if !ok { t.Errorf("Expected model_ca, got %T", fm) } @@ -242,7 +242,7 @@ func Test_EntryCA_TriggerError(t *testing.T) { keyPress(tm, "esc") fm := tm.FinalModel(t) - mm, ok := fm.(model) + mm, ok := fm.(Model) if !ok { t.Errorf("Expected model_ca, got %T", fm) } @@ -285,7 +285,7 @@ func Test_EntryCA(t *testing.T) { keyPress(tm, "esc") fm := tm.FinalModel(t) - m, ok := fm.(model) + m, ok := fm.(Model) if !ok { t.Errorf("Expected model, got %T", fm) } @@ -397,7 +397,6 @@ func TestSubmitWithRequiredField(t *testing.T) { setup() defer teardown() - m := NewGitHubUserForm(nil) tm := teatest.NewTestModel( t, m, teatest.WithInitialTermSize(300, 300), @@ -405,10 +404,10 @@ func TestSubmitWithRequiredField(t *testing.T) { // Simulate filling in the required field tm.Type("Slug-Boi") - tm.Send(tea.KeyMsg{Type: tea.KeyTab}) // Move to next field - tm.Send(tea.KeyMsg{Type: tea.KeyTab}) // Move to submit button + tm.Send(tea.KeyMsg{Type: tea.KeyTab}) // Move to next field + tm.Send(tea.KeyMsg{Type: tea.KeyTab}) // Move to submit button tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) // Submit - tm.Send(tea.KeyMsg{Type: tea.KeyTab}) + tm.Send(tea.KeyMsg{Type: tea.KeyTab}) tm.Send(tea.KeyMsg{Type: tea.KeyTab}) tm.Send(tea.KeyMsg{Type: tea.KeyTab}) tm.Type("input@mail") @@ -421,8 +420,6 @@ func TestSubmitWithRequiredField(t *testing.T) { // Check if the form was submitted updated, _ := tm.FinalModel(t).(model_ca) - - if updated.inputs[0].Value() != "th" { t.Errorf("Expected 'Slug-Boi', got '%s'", updated.inputs[0].Value()) } @@ -440,7 +437,7 @@ func TestSubmitWithRequiredField(t *testing.T) { // Test temp auth toggle visibility func TestTempAuthToggleVisibility(t *testing.T) { // With parent model (should show toggle) - m1 := NewGitHubUserForm(&model{}) + m1 := NewGitHubUserForm(&Model{}) if !m1.tempAuthShow { t.Error("tempAuthShow should be true with parent model") } @@ -454,7 +451,7 @@ func TestTempAuthToggleVisibility(t *testing.T) { // Test temp auth toggle functionality func TestTempAuthToggle(t *testing.T) { - m := NewGitHubUserForm(&model{}) + m := NewGitHubUserForm(&Model{}) // Initial state if m.tempAuth { @@ -610,7 +607,7 @@ func Test_EntrySelectUsers(t *testing.T) { keyPress(tm, "enter") fm := tm.FinalModel(t) - m, ok := fm.(model) + m, ok := fm.(Model) if !ok { t.Errorf("Expected model, got %T", fm) } @@ -640,7 +637,7 @@ func Test_EntrySelectAll(t *testing.T) { keyPress(tm, "enter") fm := tm.FinalModel(t) - m, ok := fm.(model) + m, ok := fm.(Model) if !ok { t.Errorf("Expected model, got %T", fm) } @@ -669,7 +666,7 @@ func Test_EntryNegation(t *testing.T) { keyPress(tm, "enter") fm := tm.FinalModel(t) - m, ok := fm.(model) + m, ok := fm.(Model) if !ok { t.Errorf("Expected model, got %T", fm) } @@ -700,7 +697,7 @@ func Test_EntryDeleteAuthor(t *testing.T) { keyPress(tm, "enter") fm := tm.FinalModel(t) - m, ok := fm.(model) + m, ok := fm.(Model) if !ok { t.Errorf("Expected model, got %T", fm) } @@ -733,7 +730,7 @@ func Test_GroupSelection(t *testing.T) { keyPress(tm, "enter") fm := tm.FinalModel(t) - _, ok := fm.(model) + _, ok := fm.(Model) if !ok { t.Errorf("Expected model, got %T", fm) } @@ -769,7 +766,7 @@ func Test_pagination(t *testing.T) { tm.Quit() fm := tm.FinalModel(t) - m, ok := fm.(model) + m, ok := fm.(Model) if !ok { t.Errorf("Expected model, got %T", fm) }