charmbracelet / gum

A tool for glamorous shell scripts 🎀
MIT License
17.94k stars 339 forks source link

Shell gets stuck when `--placeholder` in `gum input` contains Japanese characters #591

Open btbf opened 4 months ago

btbf commented 4 months ago

There are two issues observed:

Issue 1 When the following command is executed in the shell, there is no response:

gum input --placeholder "作業ディレクトリを指定してください"

Issue 2 When the following command is executed in the shell and the initial value set in the --value parameter is completely deleted using the backspace key, an error occurs:

gum input --value "${HOME}/cnode" --width=0 --header="作業ディレクトリを作成します。任意のパスを指定可能です。デフォルトの場合はそのままEnterを押して下さい" --header.foreground="99" --placeholder "作業ディレクトリを指定してください"

Error Details

Caught panic:

runtime error: slice bounds out of range [:34] with capacity 32

Restoring terminal...

goroutine 1 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.22.2/x64/src/runtime/debug/stack.go:24 +0x5e
runtime/debug.PrintStack()
        /opt/hostedtoolcache/go/1.22.2/x64/src/runtime/debug/stack.go:16 +0x13
github.com/charmbracelet/bubbletea.(*Program).Run.func1()
        /home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:478 +0x91
panic({0x9f1de0?, 0xc0005e01e0?})
        /opt/hostedtoolcache/go/1.22.2/x64/src/runtime/panic.go:770 +0x132
github.com/charmbracelet/bubbles/textinput.Model.placeholderView({{0x0, 0x0}, {0xc0004f5ab8, 0x2}, {0xc0004de0c0, 0x33}, 0x0, 0x2a, {0x1f972880, {0x0, ...}, ...}, ...})
        /home/runner/go/pkg/mod/github.com/charmbracelet/bubbles@v0.18.0/textinput/textinput.go:733 +0x589
github.com/charmbracelet/bubbles/textinput.Model.View({{0x0, 0x0}, {0xc0004f5ab8, 0x2}, {0xc0004de0c0, 0x33}, 0x0, 0x2a, {0x1f972880, {0x0, ...}, ...}, ...})
        /home/runner/go/pkg/mod/github.com/charmbracelet/bubbles@v0.18.0/textinput/textinput.go:657 +0x59
github.com/charmbracelet/huh.(*Input).View(0xc00050e808)
        /home/runner/go/pkg/mod/github.com/charmbracelet/huh@v0.3.1-0.20240404200615-66118a2cb3cf/field_input.go:261 +0x71d
github.com/charmbracelet/huh.(*Group).buildView(0xc0007c4488)
        /home/runner/go/pkg/mod/github.com/charmbracelet/huh@v0.3.1-0.20240404200615-66118a2cb3cf/group.go:290 +0x395
github.com/charmbracelet/huh.(*Group).Update(0xc0007c4488, {0x9e86c0, 0xc0004e6570})
        /home/runner/go/pkg/mod/github.com/charmbracelet/huh@v0.3.1-0.20240404200615-66118a2cb3cf/group.go:252 +0x3a5
github.com/charmbracelet/huh.(*Form).Update(0xc000313080, {0x9e86c0, 0xc0004e6570?})
        /home/runner/go/pkg/mod/github.com/charmbracelet/huh@v0.3.1-0.20240404200615-66118a2cb3cf/form.go:512 +0x58b
github.com/charmbracelet/bubbletea.(*Program).eventLoop(0xc0000e5520, {0x1abc210?, 0xc000313080?}, 0xc00002e060)
        /home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:411 +0x5e2
github.com/charmbracelet/bubbletea.(*Program).Run(0xc0000e5520)
        /home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:543 +0x86b
github.com/charmbracelet/huh.(*Form).run(0xc00050f801?)
        /home/runner/go/pkg/mod/github.com/charmbracelet/huh@v0.3.1-0.20240404200615-66118a2cb3cf/form.go:560 +0x37
github.com/charmbracelet/huh.(*Form).Run(0xc0007c4488?)
        /home/runner/go/pkg/mod/github.com/charmbracelet/huh@v0.3.1-0.20240404200615-66118a2cb3cf/form.go:555 +0x68
github.com/charmbracelet/gum/input.Options.Run({{0xc0004de0c0, 0x33}, {0xc0004f5ab8, 0x2}, {{0x0, 0x0}, {0x0, 0x0}, {0xc0004f5b18, 0x4}, ...}, ...})
        /home/runner/go/pkg/mod/github.com/charmbracelet/gum@v0.14.0/input/command.go:54 +0x628
reflect.Value.call({0xa01620?, 0xc0000a2fd8?, 0x417d9f?}, {0xa1e7ae, 0x4}, {0xc000809ab8, 0x0, 0x969d0e?})
        /opt/hostedtoolcache/go/1.22.2/x64/src/reflect/value.go:596 +0xca6
reflect.Value.Call({0xa01620?, 0xc0000a2fd8?, 0x9bdc80?}, {0xc000809ab8?, 0x995a40?, 0x0?})
        /opt/hostedtoolcache/go/1.22.2/x64/src/reflect/value.go:380 +0xb9
github.com/alecthomas/kong.callFunction({0xa01620?, 0xc0000a2fd8?, 0xc000809cb0?}, 0xc000702780)
        /home/runner/go/pkg/mod/github.com/alecthomas/kong@v0.9.0/callbacks.go:98 +0x45a
github.com/alecthomas/kong.(*Context).RunNode(0xc000258080, 0xc0006421e0, {0x0, 0x0, 0xc000432dc0?})
        /home/runner/go/pkg/mod/github.com/alecthomas/kong@v0.9.0/context.go:774 +0x80e
github.com/alecthomas/kong.(*Context).Run(0x987e00?, {0x0?, 0xc000705ee0?, 0x7?})
        /home/runner/go/pkg/mod/github.com/alecthomas/kong@v0.9.0/context.go:799 +0x132
main.main()
        /home/runner/go/pkg/mod/github.com/charmbracelet/gum@v0.14.0/main.go:74 +0x878
panic: interface conversion: tea.Model is nil, not *huh.Form

goroutine 1 [running]:
github.com/charmbracelet/huh.(*Form).run(0xc00050f801?)
        /home/runner/go/pkg/mod/github.com/charmbracelet/huh@v0.3.1-0.20240404200615-66118a2cb3cf/form.go:561 +0x7b
github.com/charmbracelet/huh.(*Form).Run(0xc0007c4488?)
        /home/runner/go/pkg/mod/github.com/charmbracelet/huh@v0.3.1-0.20240404200615-66118a2cb3cf/form.go:555 +0x68
github.com/charmbracelet/gum/input.Options.Run({{0xc0004de0c0, 0x33}, {0xc0004f5ab8, 0x2}, {{0x0, 0x0}, {0x0, 0x0}, {0xc0004f5b18, 0x4}, ...}, ...})
        /home/runner/go/pkg/mod/github.com/charmbracelet/gum@v0.14.0/input/command.go:54 +0x628
reflect.Value.call({0xa01620?, 0xc0000a2fd8?, 0x417d9f?}, {0xa1e7ae, 0x4}, {0xc000809ab8, 0x0, 0x969d0e?})
        /opt/hostedtoolcache/go/1.22.2/x64/src/reflect/value.go:596 +0xca6
reflect.Value.Call({0xa01620?, 0xc0000a2fd8?, 0x9bdc80?}, {0xc000809ab8?, 0x995a40?, 0x0?})
        /opt/hostedtoolcache/go/1.22.2/x64/src/reflect/value.go:380 +0xb9
github.com/alecthomas/kong.callFunction({0xa01620?, 0xc0000a2fd8?, 0xc000809cb0?}, 0xc000702780)
        /home/runner/go/pkg/mod/github.com/alecthomas/kong@v0.9.0/callbacks.go:98 +0x45a
github.com/alecthomas/kong.(*Context).RunNode(0xc000258080, 0xc0006421e0, {0x0, 0x0, 0xc000432dc0?})
        /home/runner/go/pkg/mod/github.com/alecthomas/kong@v0.9.0/context.go:774 +0x80e
github.com/alecthomas/kong.(*Context).Run(0x987e00?, {0x0?, 0xc000705ee0?, 0x7?})
        /home/runner/go/pkg/mod/github.com/alecthomas/kong@v0.9.0/context.go:799 +0x132
main.main()
        /home/runner/go/pkg/mod/github.com/charmbracelet/gum@v0.14.0/main.go:74 +0x878

OS:Ubuntu22.0 Gum:0.14.0

Zhengqbbb commented 2 months ago
gum version v0.14.1 (657c76e)
---
    osname  : Darwin
    kernel  : 23.2.0
   machine  : arm64
   version  : Darwin Kernel Version 23.2.0

Reproduction example:

gum input --placeholder '谷歌视频模型 Veo | Hello World!!!'
Caught panic:

runtime error: slice bounds out of range [:42] with capacity 36

Restoring terminal...

goroutine 1 [running]:
runtime/debug.Stack()
    /opt/hostedtoolcache/go/1.22.3/x64/src/runtime/debug/stack.go:24 +0x64
runtime/debug.PrintStack()
    /opt/hostedtoolcache/go/1.22.3/x64/src/runtime/debug/stack.go:16 +0x1c
github.com/charmbracelet/bubbletea.(*Program).Run.func1()
caarlos0 commented 2 months ago

this bug seems to be in bubbles.

we are kinda mixing the length of the string vs the uniseg length

https://github.com/charmbracelet/bubbles/blob/a9344b59531d1b947978485dea07c5597299889a/textinput/textinput.go#L728