-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * fix: added CLI exit * fix: release the terminal at the end of the run * fix: handle error terminal end error * fix: only show spinner in interactive mode * ci: remove templates after matrix ends * fix: remove ucreate main from go routine * fix: remove the channel * ffix: wait for spinner to finish * ci: removes go install from matrix job * fix: remove duplicate error handling --------- Co-authored-by: Mohammad_Alhallaq <mohammad.alhallaq1@gmail.com> Co-authored-by: MelkeyDev <53410236+Melkeydev@users.noreply.github.com>
- Loading branch information
1 parent
5062f9b
commit c713f8a
Showing
4 changed files
with
91 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package spinner | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/bubbles/spinner" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
type errMsg error | ||
|
||
type model struct { | ||
spinner spinner.Model | ||
quitting bool | ||
err error | ||
} | ||
|
||
func InitialModelNew() model { | ||
s := spinner.New() | ||
s.Spinner = spinner.Line | ||
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) | ||
return model{spinner: s} | ||
} | ||
|
||
func (m model) Init() tea.Cmd { | ||
return m.spinner.Tick | ||
} | ||
|
||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
switch msg.String() { | ||
case "q", "esc", "ctrl+c": | ||
m.quitting = true | ||
return m, tea.Quit | ||
default: | ||
return m, nil | ||
} | ||
|
||
case errMsg: | ||
m.err = msg | ||
return m, nil | ||
|
||
default: | ||
var cmd tea.Cmd | ||
m.spinner, cmd = m.spinner.Update(msg) | ||
return m, cmd | ||
} | ||
} | ||
|
||
func (m model) View() string { | ||
|
||
if m.err != nil { | ||
return m.err.Error() | ||
} | ||
str := fmt.Sprintf("\n\n %s Preparing...\n\n", m.spinner.View()) | ||
if m.quitting { | ||
return str + "\n" | ||
} | ||
return str | ||
} |
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