Skip to content
Myr

main.go

This file

Path

examples/altscreen-toggle/main.go

84 lines · 1.5 KiB · 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 0cef3c7 point at it.

feat(render): remove flickeringKonstantin Antonovbefore adoption0cef3c7

lines 1–6why, one step back
1package main
23import (4 "fmt"5 "os"6

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

lines 7–8why, one step back
7 tea "charm.land/bubbletea/v2"
8 "charm.land/lipgloss/v2"

feat(render): remove flickeringKonstantin Antonovbefore adoption0cef3c7

lines 9–30why, one step back
9)
1011var (12 keywordStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("204")).Background(lipgloss.Color("235"))13 helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241"))14)1516type model struct {17 altscreen bool18 quitting bool19 suspending bool20}2122func (m model) Init() tea.Cmd {23 return nil24}2526func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {27 switch msg := msg.(type) {28 case tea.ResumeMsg:29 m.suspending = false30 return m, nil

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

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

feat(render): remove flickeringKonstantin Antonovbefore adoption0cef3c7

lines 32–38why, one step back
32 switch msg.String() {
33 case "q", "ctrl+c", "esc":34 m.quitting = true35 return m, tea.Quit36 case "ctrl+z":37 m.suspending = true38 return m, tea.Suspend

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

line 39why, one step back
39 case "space":

feat(render): remove flickeringKonstantin Antonovbefore adoption0cef3c7

lines 40–47why, one step back
40 var cmd tea.Cmd
41 m.altscreen = !m.altscreen42 return m, cmd43 }44 }45 return m, nil46}47

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

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

feat(render): remove flickeringKonstantin Antonovbefore adoption0cef3c7

line 49why, one step back
49 if m.suspending {

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

lines 50–52why, one step back
50 v := tea.NewView("")
51 v.AltScreen = m.altscreen52 return v

feat(render): remove flickeringKonstantin Antonovbefore adoption0cef3c7

lines 53–55why, one step back
53 }
5455 if m.quitting {

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

lines 56–58why, one step back
56 v := tea.NewView("Bye!\n")
57 v.AltScreen = m.altscreen58 return v

feat(render): remove flickeringKonstantin Antonovbefore adoption0cef3c7

lines 59–72why, one step back
59 }
6061 const (62 altscreenMode = " altscreen mode "63 inlineMode = " inline mode "64 )6566 var mode string67 if m.altscreen {68 mode = altscreenMode69 } else {70 mode = inlineMode71 }72

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

lines 73–76why, one step back
73 v := tea.NewView(fmt.Sprintf("\n\n You're in %s\n\n\n", keywordStyle.Render(mode)) +
74 helpStyle.Render(" space: switch modes • ctrl-z: suspend • q: exit\n"))75 v.AltScreen = m.altscreen76 return v

feat(render): remove flickeringKonstantin Antonovbefore adoption0cef3c7

lines 77–84why, one step back
77}
7879func main() {80 if _, err := tea.NewProgram(model{}).Run(); err != nil {81 fmt.Println("Error running program:", err)82 os.Exit(1)83 }84}