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

textinput: when Width is larger than the capacity of the placeholder, it causes a panic #531

Open
MikaelFangel opened this issue May 30, 2024 · 0 comments · May be fixed by #532
Open

textinput: when Width is larger than the capacity of the placeholder, it causes a panic #531

MikaelFangel opened this issue May 30, 2024 · 0 comments · May be fixed by #532

Comments

@MikaelFangel
Copy link
Contributor

Describe the bug
When you increase the width above 31 and the placeholder capacity is set to 32, the program panics. This bug is causing the bug reported here charmbracelet/gum#591 as far as I can tell.

To Reproduce
Steps to reproduce the behavior:

  1. Run the code with a ti.Width of 31
  2. Run the code and see it works just fine
  3. Change the value to 32
  4. Run the code a see the out-of-bounds panic

Source Code

package main

import (
	"fmt"
	"log"

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

func main() {
	p := tea.NewProgram(initialModel())
	if _, err := p.Run(); err != nil {
		log.Fatal(err)
	}
}

type model struct {
	textInput textinput.Model
	err       error
}

func initialModel() model {
	ti := textinput.New()
	ti.Placeholder = "作業ディレクトリを指定してください"
	ti.Width = 32

	return model{
		textInput: ti,
		err:       nil,
	}
}

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

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	return m, nil
}

func (m model) View() string {
	return fmt.Sprintf(
		m.textInput.View(),
	) + "\n"
}

Expected behavior
The placeholder capacity should not cause out-of-bounds panics based on the ti.Width.

Screenshots
p getting a default capacity of 32
20240530_11h39m01s_grim

The minWidth exceeds the capacity
20240530_11h40m06s_grim

The out-of-bounds slide happening
20240530_11h41m16s_grim

@MikaelFangel MikaelFangel linked a pull request May 30, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant