Skip to content

Commit

Permalink
fix: print errors for form aborts
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Jan 29, 2024
1 parent 3a96154 commit 1dd48e0
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func runForm(config *Config) (*Config, error) {

theme := huh.ThemeCharm()
theme.FieldSeparator = lipgloss.NewStyle()
theme.Blurred.TextInput.Text = theme.Blurred.TextInput.Text.Copy().Foreground(lipgloss.Color("243"))
theme.Blurred.Title = theme.Blurred.Title.Copy().Width(14).Foreground(lipgloss.Color("7"))
theme.Focused.Title = theme.Focused.Title.Copy().Width(14).Foreground(green).Bold(true)
theme.Focused.Title = theme.Focused.Title.Copy().Width(14).Foreground(green).Bold(true)
theme.Blurred.Description = theme.Blurred.Description.Copy().Foreground(lipgloss.Color("0"))
theme.Focused.Description = theme.Focused.Description.Copy().Foreground(lipgloss.Color("7"))
theme.Blurred.BlurredButton = lipgloss.NewStyle().Foreground(lipgloss.Color("8")).PaddingRight(1)
Expand All @@ -44,14 +44,23 @@ func runForm(config *Config) (*Config, error) {
theme.Blurred.NoteTitle = theme.Blurred.NoteTitle.Copy().Margin(1, 0)

if config.Input == "" {
_ = huh.NewForm(
err := huh.NewForm(
huh.NewGroup(
huh.NewNote().Title("Capture file"),
huh.NewFilePicker().
Height(10).
Value(&config.Input),
),
).WithTheme(theme).Run()
).
WithTheme(theme).
Run()

if err != nil {
printErrorFatal("Something went wrong", err)
}
if config.Input == "" {
printErrorFatal("No chosen file", errors.New("Try again"))
}

base, ext := filepath.Base(config.Input), filepath.Ext(config.Input)
config.Output = strings.TrimSuffix(base, ext) + ".svg"
Expand Down Expand Up @@ -161,7 +170,7 @@ func runForm(config *Config) (*Config, error) {
Value(&borderWidth).
Validate(validateInteger),

huh.NewInput().Title("Border color ").
huh.NewInput().Title("Border Color ").
// Description("Color of outline stroke.").
Validate(validateColor).
Inline(true).
Expand Down

0 comments on commit 1dd48e0

Please sign in to comment.