-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): ensure correct help bar shown
Also consolidates help-bar construction logic
- Loading branch information
Showing
7 changed files
with
139 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package scope_selector | ||
|
||
import ( | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/skalt/git-cc/pkg/config" | ||
"github.com/skalt/git-cc/pkg/parser" | ||
"github.com/skalt/git-cc/pkg/single_select" | ||
) | ||
|
||
var helpBar = config.HelpBar( | ||
config.HelpSubmit, config.HelpSelect, config.HelpBack, config.HelpCancel, | ||
) | ||
|
||
type Model struct { | ||
input single_select.Model | ||
} | ||
|
||
func NewModel(cc *parser.CC, cfg config.Cfg) Model { | ||
return Model{ | ||
single_select.NewModel( | ||
config.Faint("select a scope:"), | ||
cc.Scope, | ||
append( | ||
[]map[string]string{{"": "unscoped; affects the entire project"}}, | ||
cfg.Scopes..., | ||
), | ||
), // TODO: Option to add new scope? | ||
} | ||
} | ||
|
||
func (m Model) Value() string { | ||
return m.input.Value() | ||
} | ||
|
||
func (m Model) View() string { | ||
return m.input.View() + helpBar | ||
} | ||
|
||
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
m.input, cmd = m.input.Update(msg) | ||
return m, cmd | ||
} | ||
|
||
func (m Model) ShouldSkip(currentValue string) bool { | ||
if len(m.input.Options) == 0 { | ||
return true | ||
} | ||
for _, opt := range m.input.Options { | ||
if currentValue == opt && opt != "" { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package type_selector | ||
|
||
import ( | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/skalt/git-cc/pkg/config" | ||
"github.com/skalt/git-cc/pkg/parser" | ||
"github.com/skalt/git-cc/pkg/single_select" | ||
) | ||
|
||
var helpBar = config.HelpBar( | ||
config.HelpSubmit, config.HelpSelect, config.HelpCancel, | ||
) | ||
|
||
type Model struct { | ||
input single_select.Model | ||
} | ||
|
||
func NewModel(cc *parser.CC, cfg config.Cfg) Model { | ||
return Model{ | ||
single_select.NewModel( | ||
config.Faint("select a commit type: "), cc.Type, cfg.CommitTypes, | ||
), | ||
} | ||
} | ||
|
||
func (m Model) Value() string { | ||
return m.input.Value() | ||
} | ||
|
||
func (m Model) View() string { | ||
return m.input.View() + helpBar | ||
} | ||
|
||
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
m.input, cmd = m.input.Update(msg) | ||
return m, cmd | ||
} | ||
|
||
func (m Model) ShouldSkip(currentValue string) bool { | ||
for _, opt := range m.input.Options { | ||
if opt == currentValue { | ||
return true | ||
} | ||
} | ||
return false | ||
} |