charmbracelet / charmbracelet/vhs

Can't combine Shift and Down

Open
#641 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
20.9k
Forks
474
Avg merge
4d 1h
Merged PRs (30d)
2

Description

**Describe the bug**
I can't find a way to simulate the user holding shift and pressing down.

At fist I tried to implement this manually in the script, but nothing I tried worked. This is everything I tried and got compile errors:
```
Shift Down
Shift Down 1
Shift+Down
Key "shift" "down"
Key "shift+down"
```

I then tried to use `vhs record` to create what I needed. Performing a shift down in a recording session produces the following which does nothing when trying to record a demo using the script.

```
Type "[1;2B"
```

**Setup**
Please complete the following information along with version numbers, if applicable.
- OS: macOS
- Shell: zsh
- Terminal Emulator: iterm
- Terminal Multiplexer: tmux

**To Reproduce**
Use the min example I put in the source code and run this vhs demo tape:

```
Output demo.gif

Set Framerate 10
Set Shell zsh
Set FontSize 24
Set Width 1200
Set Height 600

Type "go run main.go"
Sleep 1s
Enter
Sleep 2s

# Test shift down from vhs record:
Type "[1;2B"
Type "[1;2B"
Type "[1;2B"
Sleep 5s
```

**Source Code**

```go
package main

import (
"fmt"
"log"
"os"

tea "github.com/charmbracelet/bubbletea"
)

type model struct {
events []string
}

func (m model) Init() tea.Cmd {
return nil
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "q", "ctrl+c", "esc":
return m, tea.Quit
case "shift+down":
m.events = append(m.events, "Got shift+down!")
default:
m.events = append(m.events, fmt.Sprintf("Got key: %q", msg.String()))
}

// Keep only last 10 events
if len(m.events) > 10 {
m.events = m.events[len(m.events)-10:]
}
}
return m, nil
}

func (m model) View() string {
s := "Shift+Down Key Event Test\n"
s += "========================\n\n"
s += "Press Shift+Down to test the key event\n"
s += "Press 'q' or 'esc' to quit\n\n"
s += "Recent events:\n"

for _, event := range m.events {
s += " " + event + "\n"
}

return s
}

func main() {
p := tea.NewProgram(model{events: []string{}})
if _, err := p.Run(); err != nil {
log.Fatal(err)
os.Exit(1)
}
}
```

**Expected behavior**
`Got shift+down!` should be printed three times, but instead every key in the Type statement is sent.

**Screenshots**
Add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start with the supplied main.go reproduction and the vhs record workflow, then trace how the Type statement handles the recorded sequence `[1;2B`. Verify whether the input is interpreted as Shift+Down rather than literal text, and rerun the tape to confirm that `Got shift+down!` appears three times.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.