Skip to content

Commit

Permalink
Add altscreen toggling to exec demo
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Mar 1, 2022
1 parent 5cd97b7 commit 3667b41
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/exec/main.go
Expand Up @@ -13,7 +13,8 @@ var (
)

type model struct {
err error
altscreenActive bool
err error
}

func (m model) Init() tea.Cmd {
Expand All @@ -24,6 +25,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "a":
m.altscreenActive = !m.altscreenActive
cmd := tea.EnterAltScreen
if !m.altscreenActive {
cmd = tea.ExitAltScreen
}
return m, cmd
case "e":
if err := p.ReleaseTerminal(); err != nil {
m.err = err
Expand Down Expand Up @@ -52,7 +60,7 @@ func (m model) View() string {
if m.err != nil {
return "Error: " + m.err.Error()
}
return "Press e to open Vim. Press q to quit."
return "Press 'e' to open your EDITOR.\nPress 'a' to toggle the altscreen\nPress 'q' to quit.\n"
}

func main() {
Expand Down

0 comments on commit 3667b41

Please sign in to comment.