-
Notifications
You must be signed in to change notification settings - Fork 832
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
Windows: first character input lost on successive programs #1167
Comments
hi @jtackaberry I would like to work on this, could you assign me |
Go for it, @Denish3436 ✌️ |
Hii @meowgorithm , can you please review my PR |
Hey @Denish3436! Ayman's reviewed it in #1180. Let's track progress over there. |
@Denish3436 This should be fixed in |
Hi @aymanbagabas, I'm still getting that problem with the Example file: package main
import (
"fmt"
"log"
"os"
tea "github.com/charmbracelet/bubbletea/v2"
)
type model struct {
v string
}
func NewModel() model {
return model{v: ""}
}
func (m model) Init() (tea.Model, tea.Cmd) {
return m, nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
// Is it a key press?
case tea.KeyMsg:
log.Println("key pressed:", msg.String())
switch msg.String() {
case "ctrl+c", "enter":
return m, tea.Quit
default:
m.v += msg.String()
}
}
return m, nil
}
func (m model) View() string {
return "> " + m.v
}
func main() {
file := "debug.log"
// Check if the file exists
if _, err := os.Stat(file); err == nil {
// File exists, attempt to remove it
if err := os.Remove(file); err != nil {
// Handle error during removal
panic(err)
}
} else if !os.IsNotExist(err) {
// Handle unexpected error during Stat
panic(err)
}
f, err := tea.LogToFile(file, "debug")
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
}
defer f.Close()
p := tea.NewProgram(NewModel())
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
p2 := tea.NewProgram(NewModel())
if _, err := p2.Run(); err != nil {
fmt.Printf("Alas, there's been an error 2: %v", err)
os.Exit(1)
}
} A keypress is swallowed for the second program and each key is duplicated in the stdout: Actual key presses:
Any pointers? |
Hi @nojaf. You're getting duplicate keys because you're listening for This should fix that for you: - case tea.KeyMsg:
+ case tea.KeyPressMsg: Now, running your examples with the latest
I'm using Windows Terminal Preview on Windows 11 with the default PowerShell version. |
Hey @aymanbagabas, thanks for the quick feedback! The
I did press |
Describe the bug
On Windows, if multiple Tea programs are run successively within the same process, the first program runs fine, but subsequent programs lose the first key pressed. The key is silently eaten, after which point the program appears to operate properly until it terminates. Then rinse/repeat for subsequent Tea programs.
This does not occur on Linux or Mac.
Setup
To Reproduce
Source Code
Expected behavior
The first key on subsequent Tea programs should not be lost.
Screenshots
The text was updated successfully, but these errors were encountered: