Skip to content
Myr

main.go

This file

Path

examples/suspend/main.go

57 lines · 981 bytes · Go

Last changed by

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

History of this file

Take it

The walk stopped after 200 commits: lines older than 3dfbcd9 point at it.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 1–3why, one step back
1package main
23import (

feat(SIGINT): better handle interrupts (#1255)Carlos Alexandro Beckerbefore adoptioncb93959

line 4why, one step back
4 "errors"

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 5–7why, one step back
5 "fmt"
6 "os"7

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 8why, one step back
8 tea "charm.land/bubbletea/v2"

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 9–24why, one step back
9)
1011type model struct {12 quitting bool13 suspending bool14}1516func (m model) Init() tea.Cmd {17 return nil18}1920func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {21 switch msg := msg.(type) {22 case tea.ResumeMsg:23 m.suspending = false24 return m, nil

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 25why, one step back
25 case tea.KeyPressMsg:

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 26why, one step back
26 switch msg.String() {

feat(SIGINT): better handle interrupts (#1255)Carlos Alexandro Beckerbefore adoptioncb93959

line 27why, one step back
27 case "q", "esc":

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 28–29why, one step back
28 m.quitting = true
29 return m, tea.Quit

feat(SIGINT): better handle interrupts (#1255)Carlos Alexandro Beckerbefore adoptioncb93959

lines 30–32why, one step back
30 case "ctrl+c":
31 m.quitting = true32 return m, tea.Interrupt

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 33–40why, one step back
33 case "ctrl+z":
34 m.suspending = true35 return m, tea.Suspend36 }37 }38 return m, nil39}40

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 41why, one step back
41func (m model) View() tea.View {

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 42why, one step back
42 if m.suspending || m.quitting {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 43why, one step back
43 return tea.NewView("")

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 44–45why, one step back
44 }
45

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 46why, one step back
46 return tea.NewView("\nPress ctrl-z to suspend, ctrl+c to interrupt, q, or esc to exit\n")

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 47–51why, one step back
47}
4849func main() {50 if _, err := tea.NewProgram(model{}).Run(); err != nil {51 fmt.Println("Error running program:", err)

feat(SIGINT): better handle interrupts (#1255)Carlos Alexandro Beckerbefore adoptioncb93959

lines 52–54why, one step back
52 if errors.Is(err, tea.ErrInterrupted) {
53 os.Exit(130)54 }

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 55–57why, one step back
55 os.Exit(1)
56 }57}