mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-26 10:04:17 +02:00
Nice looking system-level errors
This commit is contained in:
parent
939fdef913
commit
5cd6accce3
1 changed files with 19 additions and 1 deletions
20
ui/ui.go
20
ui/ui.go
|
|
@ -126,6 +126,13 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
}, tea.Quit
|
||||
}
|
||||
|
||||
// If there's been an error, any key exits
|
||||
if m.err != nil {
|
||||
if _, ok := msg.(tea.KeyMsg); ok {
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
cmd tea.Cmd
|
||||
cmds []tea.Cmd
|
||||
|
|
@ -277,7 +284,7 @@ func view(mdl tea.Model) string {
|
|||
}
|
||||
|
||||
if m.err != nil {
|
||||
return fmt.Sprintf("\nError: %v\n\nPress q to exit.", m.err)
|
||||
return "\n" + indent(errorView(m.err), 2)
|
||||
}
|
||||
|
||||
var s string
|
||||
|
|
@ -298,6 +305,17 @@ func view(mdl tea.Model) string {
|
|||
return "\n" + indent(s, 2)
|
||||
}
|
||||
|
||||
func errorView(err error) string {
|
||||
return fmt.Sprintf("%s\n\n%v\n\n%s",
|
||||
te.String(" ERROR ").
|
||||
Foreground(common.Cream.Color()).
|
||||
Background(common.Red.Color()).
|
||||
String(),
|
||||
err,
|
||||
common.Subtle("Press any key to exit"),
|
||||
)
|
||||
}
|
||||
|
||||
// COMMANDS
|
||||
|
||||
func listenForTerminalResize() tea.Cmd {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue