c-bata / go-prompt

Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.
https://godoc.org/github.com/c-bata/go-prompt
MIT License
5.29k stars 348 forks source link

[Bug] When starting docker image with CMD it panics #154

Open JesterOrNot opened 4 years ago

JesterOrNot commented 4 years ago

Bug reports

Please file a bug report here.

Expected Behavior

program works as expected

Current Behavior and Steps to Reproduce

image I start docker image

FROM homebrew/brew as build

RUN brew install gosh-terminal/gosh/gosh

RUN useradd -s /home/linuxbrew/.linuxbrew/bin/gosh gosh-user
USER gosh-user
ENV SHELL=/home/linuxbrew/.linuxbrew/bin/gosh
CMD ["/bin/bash", "-c", "gosh"]

starts and I am unable to use input when you click enter it crashes

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

here is the code

command := prompt.Input("", Completer, prompt.OptionHistory(GetCommandHist()), prompt.OptionSuggestionBGColor(prompt.DefaultColor),
            prompt.OptionInputTextColor(prompt.Cyan),
            prompt.OptionMaxSuggestion(6),
            prompt.OptionTitle("gosh"),
            prompt.OptionAddKeyBind(prompt.KeyBind{
                Key: prompt.ControlC,
                Fn: func(buf *prompt.Buffer) {
                    ThePrompt()
                }}),
JesterOrNot commented 4 years ago

Any updates on this issue?

JesterOrNot commented 4 years ago

Any updates on this?

mceloud commented 4 years ago

I hit the same issue using KVM in vnc console. Also tried to run from latest revision, but with no luck. Is there any update?

have the issue with just starting the binary inside:

[vesbkp@master-0 ~]$ vpmu
panic: runtime error: integer divide by zero

goroutine 1 [running]:
marek/vpm/vendor/github.com/c-bata/go-prompt.(*Render).toPos(...)
    /go/src/marek/vpm/vendor/github.com/c-bata/go-prompt/render.go:268
marek/vpm/vendor/github.com/c-bata/go-prompt.(*Render).move(0xc000028000, 0x1a, 0x0, 0x4)
    /go/src/marek/vpm/vendor/github.com/c-bata/go-prompt/render.go:257 +0xcc
marek/vpm/vendor/github.com/c-bata/go-prompt.(*Render).clear(0xc000028000, 0x1a)
    /go/src/marek/vpm/vendor/github.com/c-bata/go-prompt/render.go:244 +0x3e
marek/vpm/vendor/github.com/c-bata/go-prompt.(*Render).BreakLine(0xc000028000, 0xc000328040)
    /go/src/marek/vpm/vendor/github.com/c-bata/go-prompt/render.go:231 +0x209
marek/vpm/vendor/github.com/c-bata/go-prompt.(*Prompt).feed(0xc00015e000, 0xc000365400, 0x1, 0x400, 0x1, 0x5)
    /go/src/marek/vpm/vendor/github.com/c-bata/go-prompt/prompt.go:120 +0x2a6
marek/vpm/vendor/github.com/c-bata/go-prompt.(*Prompt).Run(0xc00015e000)
    /go/src/marek/vpm/vendor/github.com/c-bata/go-prompt/prompt.go:72 +0x570
main.main()
    /go/src/marek/vpm/cmd/vpmu/main.go:77 +0x206
JesterOrNot commented 4 years ago

So it errors during any kind of virtualization hmm.

mceloud commented 4 years ago

I debugged a little and to root cause is that rows and cols are set to 0 size in console

$ stty size
0 0

changing the size worked for me $ stty cols 83 rows 40