Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to send and record some alt modifier sequences #442

Open
mikelorant opened this issue Feb 4, 2024 · 5 comments
Open

Unable to send and record some alt modifier sequences #442

mikelorant opened this issue Feb 4, 2024 · 5 comments

Comments

@mikelorant
Copy link
Contributor

Describe the bug
Sending and recording alt modifier sequences with alphanumeric key presses does not work.

Setup
Please complete the following information along with version numbers, if applicable.

  • macOS
  • zsh
  • iTerm2

For macOS showkey needs to be installed:

brew install showkey

For Linux use:

showkey -a

To Reproduce

Sending

Here is a tape file demonstrating the sending problem:

Output alts.gif
Sleep 1s
Type "showkey" Enter Sleep 1s
Alt+S
Sleep 1s
Ctrl+C
Ctrl+D

Incorrect output:

Type any key to see the sequence it sends.
Terminate with your shell interrupt <CTL-C=ETX> or quit <FS> character.
S

Recording

Steps:

  1. vhs record > alt.tape
  2. showkey
  3. Press ALT and S
  4. Press CTRL and C to quit showkey
  5. Press CTRL and D to end recording
  6. cat alt.tape | grep Alt

Expected behavior

Sending

The showkey output should display:

Type any key to see the sequence it sends.
Terminate with your shell interrupt <CTL-C=ETX> or quit <FS> character.
<ESC>S

Recording

The alt.tape should display:

Alt+S

Screenshots
Incorrect result:
alts-before

Correct output:
alts-after

@mikelorant
Copy link
Contributor Author

See pull request #441 for the fix to both these issues.

The correct output displayed in the screenshot section is the result from the fixed branch.

@mikelorant
Copy link
Contributor Author

@maaslalani Are you able to verify this issue exists for you as well?

@mikelorant
Copy link
Contributor Author

@maaslalani You probably missed this issue with the flurry of issues and pull requests I have been creating.

Can we verify this issue is reproducible and check that the pull request does fix the issue?

@mikelorant
Copy link
Contributor Author

I am basing alt on what Bubbletea defines it as. This might need a lot more thinking about how we handle this.

@mikelorant
Copy link
Contributor Author

mikelorant commented Mar 5, 2024

Definition

I think it is important to firstly clarify what the alt key means.

For me, on a Mac, I am pressing the option key which has been configured by iTerm2 to send Esc+.

We need to remove what terminal and OS (and even keyboard) is being used and just look at it as messages. What really matters is what alt means in the Charm ecosystem. If I build a Bubbletea app that does an action when pressing alt, I should expect something to happen.

Therefore, let's base the answer on what tea.KeyMsg sees.

Testing

So we need two parts to prove this.

  1. Bubbletea application that responds to alt key presses.
  2. VHS tape that sends this key press.

Application

The following code is a short Bubbletea application that responds to alt + s. Using the string key message means we can be sure we are handling the exact case we are targeting.

package main

import (
	"fmt"

	tea "github.com/charmbracelet/bubbletea"
)

type Model struct {
	state bool
	text string
}

func main() {
	p := tea.NewProgram(Model{
		state: false,
		text: "disabled",
	})
	if _, err := p.Run(); err != nil {
		panic(err)
	}
}

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 "alt+s":
			switch m.state {
			case true:
				m.text = "disabled"
				m.state = false
			default:
				m.text = "enabled"
				m.state = true
			}
		case "ctrl+c", "q":
			return m, tea.Quit
		}
	}

	return m, nil
}

func (m Model) View() string {
	return fmt.Sprintf("Press Alt+S to toggle state\nState: %v\n", m.text)
}

Tape

Now lets add a VHS tape that will run this app and send the alt + s key a few times. Recommending doing a go run . before using this script to make sure it starts quickly and doesn't miss the alt + s key presses.

Output alts.gif
Type "go run ."
Enter
Sleep 1s
Alt+S
Sleep 1s
Alt+S
Sleep 1s
Ctrl+C
Ctrl+D

Results

All that was needed was to now run VHS on this tape:

vhs alts.tape

VHS stable release

I have used the current release provided by Homebrew. Reported version is:

❯ vhs --version
vhs version v0.7.1 (537d03a)

vhs-alts-stable

As you can see, nothing happens.

VHS branch fix/alt

This is using the code I have provided in pull request #441.

vhs-alts-branch-fix-alt

This shows the text message toggles.

Outcome

Based on these results I conclude that the current VHS implementation sending some alt key presses isn't working as expected.

@maaslalani Let me know if there is any further details you need me to provide so we can understand what the correct solution is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant