Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Nov 9, 2023
1 parent 80ff318 commit e39c1cd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
6 changes: 4 additions & 2 deletions field_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/charmbracelet/lipgloss"
)

const choiceConfirmation = "Chose: "

// Confirm is a form confirm field.
type Confirm struct {
value *bool
Expand Down Expand Up @@ -179,9 +181,9 @@ func (c *Confirm) runAccessible() error {
choice := accessibility.PromptBool()
*c.value = choice
if choice {
fmt.Println(c.theme.Focused.SelectedOption.Render("Chose: " + c.affirmative))
fmt.Println(c.theme.Focused.SelectedOption.Render(choiceConfirmation + c.affirmative))
} else {
fmt.Println(c.theme.Focused.SelectedOption.Render("Chose: " + c.negative))
fmt.Println(c.theme.Focused.SelectedOption.Render(choiceConfirmation + c.negative))
}
fmt.Println()
return nil
Expand Down
2 changes: 1 addition & 1 deletion field_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (s *Select[T]) runAccessible() error {
fmt.Println(err.Error())
continue
}
fmt.Println(s.theme.Focused.SelectedOption.Render("Chose: " + option.Key + "\n"))
fmt.Println(s.theme.Focused.SelectedOption.Render(choiceConfirmation + option.Key + "\n"))
*s.value = option.Value
break
}
Expand Down
5 changes: 1 addition & 4 deletions field_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ func getEditor() (string, []string) {
//
// The first argument provided is used as the editor command (vim, nvim, nano, etc...)
// The following (optional) arguments provided are passed as arguments to the editor command.
//
// .Editor("vim")
// .Editor("vim", "+10")
func (t *Text) Editor(editor ...string) *Text {
if len(editor) > 0 {
t.editorCmd = editor[0]
Expand Down Expand Up @@ -185,7 +182,7 @@ func (t *Text) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
ext := strings.TrimPrefix(t.editorExtension, ".")
tmpFile, _ := os.CreateTemp(os.TempDir(), "*."+ext)
cmd := exec.Command(t.editorCmd, append(t.editorArgs, tmpFile.Name())...) //nolint:gosec
_ = os.WriteFile(tmpFile.Name(), []byte(t.textarea.Value()), 0600)
_ = os.WriteFile(tmpFile.Name(), []byte(t.textarea.Value()), os.ModePerm)
cmds = append(cmds, tea.ExecProcess(cmd, func(error) tea.Msg {
content, _ := os.ReadFile(tmpFile.Name())
return updateValueMsg(content)
Expand Down
6 changes: 4 additions & 2 deletions form.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type Form struct {
keymap *KeyMap
}

const defaultWidth = 80

// NewForm returns a form with the given groups and default themes and
// keybindings.
//
Expand All @@ -73,7 +75,7 @@ func NewForm(groups ...*Group) *Form {
paginator: p,
theme: NewCharmTheme(),
keymap: NewDefaultKeyMap(),
width: 80,
width: defaultWidth,
}

// NB: If dynamic forms come into play this will need to be applied when
Expand Down Expand Up @@ -209,7 +211,7 @@ func (f *Form) WithWidth(width int) *Form {

// Init initializes the form.
func (f *Form) Init() tea.Cmd {
var cmds []tea.Cmd
cmds := make([]tea.Cmd, len(f.groups))
for _, group := range f.groups {
cmds = append(cmds, group.Init())
}
Expand Down
5 changes: 1 addition & 4 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,12 @@ func prevField() tea.Msg {

// Init initializes the group.
func (g *Group) Init() tea.Cmd {
var cmds []tea.Cmd

cmds := make([]tea.Cmd, len(g.fields)+1)
for _, field := range g.fields {
cmds = append(cmds, field.Init())
}

cmd := g.fields[g.paginator.Page].Focus()
cmds = append(cmds, cmd)

return tea.Batch(cmds...)
}

Expand Down
7 changes: 5 additions & 2 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ type Option[T any] struct {

// NewOptions returns new options from a list of values.
func NewOptions[T any](values ...T) []Option[T] {
var options []Option[T]
options := make([]Option[T], len(values))
for _, o := range values {
options = append(options, Option[T]{Key: fmt.Sprint(o), Value: o})
options = append(options, Option[T]{
Key: fmt.Sprint(o),
Value: o,
})
}
return options
}
Expand Down
4 changes: 2 additions & 2 deletions theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func (t Theme) copy() Theme {
}
}

// FieldStyles are the styles for input fields
// FieldStyles are the styles for input fields.
type FieldStyles struct {
Base lipgloss.Style
Title lipgloss.Style
Description lipgloss.Style
Help lipgloss.Style // TODO: apply help coloring in theme to help bubble
Help lipgloss.Style // XXX: apply help coloring in theme to help bubble
ErrorIndicator lipgloss.Style
ErrorMessage lipgloss.Style

Expand Down

0 comments on commit e39c1cd

Please sign in to comment.