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

Windows: first character input lost on successive programs #1167

Open
jtackaberry opened this issue Sep 24, 2024 · 5 comments
Open

Windows: first character input lost on successive programs #1167

jtackaberry opened this issue Sep 24, 2024 · 5 comments
Assignees

Comments

@jtackaberry
Copy link

jtackaberry commented Sep 24, 2024

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

  • OS: Windows
  • Shell: cmd and Powershell (both affected)
  • Terminal Emulator: Windows Terminal, Windows Powershell Console, Command Prompt
  • Terminal Multiplexer: none

To Reproduce

  1. Build the example in the source code section for windows
  2. Run it
  3. Type some keys for the first input prompt ("Test 0") and note that it works fine
  4. Type a key for the second input prompt ("Test 1") and note that the first key is eaten, and subsequent keys presses are registered

Source Code

package main

import (
	"fmt"

	"github.com/charmbracelet/bubbles/cursor"
	"github.com/charmbracelet/bubbles/textinput"
	tea "github.com/charmbracelet/bubbletea"
)

func Input(prompt, value string) {
	ti := textinput.New()
	ti.Prompt = prompt
	ti.Focus()
	p := tea.NewProgram(inputModel{textInput: ti})
	p.Run()
}

type inputModel struct {
	textInput textinput.Model
	quitting  bool
}

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

func (m inputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	var cmd tea.Cmd

	switch msg := msg.(type) {
	case tea.KeyMsg:
		switch msg.Type {
		case tea.KeyEnter:
			m.textInput.Cursor.SetMode(cursor.CursorHide)
			m.quitting = true
			return m, tea.Quit
		}
	}
	m.textInput, cmd = m.textInput.Update(msg)
	return m, cmd
}

func (m inputModel) View() string {
	str := m.textInput.View()
	if m.quitting {
		return str + "\n"
	}
	return str
}

func main() {
	for i := range 2 {
		Input(fmt.Sprintf("Test %d: ", i), "default")
	}
}

Expected behavior

The first key on subsequent Tea programs should not be lost.

Screenshots

image

@Denish3436
Copy link

Denish3436 commented Oct 9, 2024

hi @jtackaberry I would like to work on this, could you assign me

@meowgorithm
Copy link
Member

Go for it, @Denish3436 ✌️

@Denish3436
Copy link

Hii @meowgorithm , can you please review my PR

@meowgorithm
Copy link
Member

Hey @Denish3436! Ayman's reviewed it in #1180. Let's track progress over there.

@aymanbagabas
Copy link
Member

@Denish3436 This should be fixed in v2-exp

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

4 participants