Skip to content

Commit

Permalink
fix: 🐛 (#23) fix issue with ctrl+c
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasAugustin committed Aug 18, 2023
1 parent ed8d7ee commit f0b9566
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions pkg/ui/list.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ui

import (
"fmt"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
log "github.com/sirupsen/logrus"
"os"
)

Expand All @@ -29,6 +29,8 @@ func (m *listModel[K]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch keypress := msg.String(); keypress {
case "ctrl+c":
m.quitting = true
log.Warn("ctrl + c pressed -> quitting")
os.Exit(0)
return m, tea.Quit

case "enter":
Expand Down Expand Up @@ -68,7 +70,7 @@ func ListRun[K interface{ FilterValue() string }](settings ListSettings, input [
p := tea.NewProgram(&m, tea.WithAltScreen())

if _, err := p.Run(); err != nil {
fmt.Println("Error running program:", err)
log.Errorf("Error running program:", err)

Check failure on line 73 in pkg/ui/list.go

View workflow job for this annotation

GitHub Actions / golanglint

printf: github.com/sirupsen/logrus.Errorf call has arguments but no formatting directives (govet)

Check failure on line 73 in pkg/ui/list.go

View workflow job for this annotation

GitHub Actions / go (1.20, ubuntu-latest)

github.com/sirupsen/logrus.Errorf call has arguments but no formatting directives

Check failure on line 73 in pkg/ui/list.go

View workflow job for this annotation

GitHub Actions / go (1.19, ubuntu-latest)

github.com/sirupsen/logrus.Errorf call has arguments but no formatting directives

Check failure on line 73 in pkg/ui/list.go

View workflow job for this annotation

GitHub Actions / golanglint

printf: github.com/sirupsen/logrus.Errorf call has arguments but no formatting directives (govet)

Check failure on line 73 in pkg/ui/list.go

View workflow job for this annotation

GitHub Actions / go (1.19, ubuntu-latest)

github.com/sirupsen/logrus.Errorf call has arguments but no formatting directives
os.Exit(1)
}
return m.choice
Expand Down
12 changes: 7 additions & 5 deletions pkg/ui/spinner.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package ui

// A simple program demonstrating the spinner component from the Bubbles
// component library.

import (
"fmt"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
log "github.com/sirupsen/logrus"
"os"
)

type errMsgSpinner error

type spinnerModel struct {
spinner spinner.Model
quitting bool
err error
quitting bool
}

func initialSpinnerModel() spinnerModel {
Expand All @@ -36,6 +34,8 @@ func (m *spinnerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "q", "esc", "ctrl+c":
m.quitting = true
log.Warn("ctrl + c -> quitting")
os.Exit(0)
return m, tea.Quit
default:
return m, nil
Expand Down Expand Up @@ -78,7 +78,9 @@ func NewSpinner() Spinner {

func (s *Spinner) Run() {
go func() {
if _, err := s.program.Run(); err != nil {
_, err := s.program.Run()

if err != nil {
fmt.Println(err)
os.Exit(1)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/ui/textinputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type textInputsModel struct {
title string
inputs []textinput.Model
cursorMode cursor.Mode
quitting bool
}

func initialTextInputsModel(title string, textInputsData []pkg.TextInputData) textInputsModel {
Expand Down Expand Up @@ -58,6 +59,9 @@ func (m *textInputsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "esc":
m.quitting = true
log.Warn("ctrl + c -> quitting")
os.Exit(0)
return m, tea.Quit

// Change cursor mode
Expand Down Expand Up @@ -165,6 +169,11 @@ func TextInputsRun(title string, textInputsData []pkg.TextInputData) []pkg.TextI
log.Errorf("could not start program: %s\n", err)
os.Exit(1)
}

if model.quitting {
log.Warn("ctrl + c -> quitting")
os.Exit(0)
}
mapped := make([]pkg.TextInputRes, len(textInputsData))

for i, e := range textInputsData {
Expand Down

0 comments on commit f0b9566

Please sign in to comment.