[GH-ISSUE #556] ANSI example cannot run due to panic #407

Closed
opened 2026-03-04 01:04:42 +03:00 by kerem · 12 comments
Owner

Originally created by @tculp on GitHub (Jan 26, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/556

If trying to run the ANSI example (https://github.com/rivo/tview/wiki/ANSI), the code panics on line 25:

=> docker run -it --rm -w /go -e GO111MODULE=auto -v "${PWD}/main.go:/go/main.go" golang
root@608d711d1786:/go# go get "github.com/rivo/tview"
root@608d711d1786:/go# ls -l --color=always | go run main.go
panic: inappropriate ioctl for device

goroutine 1 [running]:
main.main()
        /main.go:25 +0x39f
exit status 2
root@608d711d1786:/#

Even echo 'hello' | go run main.go fails with the same panic.

I have confirmed this behavior both in a fresh container, and natively.

OS: MacOS
Terminal: iTerm2
Go version(s):

  • go version go1.14.4 darwin/amd64
  • go version go1.15.6 darwin/amd64
  • go version go1.15.7 darwin/amd64
  • go version go1.15.7 linux/amd64
Originally created by @tculp on GitHub (Jan 26, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/556 If trying to run the ANSI example (https://github.com/rivo/tview/wiki/ANSI), the code panics on line 25: ``` => docker run -it --rm -w /go -e GO111MODULE=auto -v "${PWD}/main.go:/go/main.go" golang root@608d711d1786:/go# go get "github.com/rivo/tview" root@608d711d1786:/go# ls -l --color=always | go run main.go panic: inappropriate ioctl for device goroutine 1 [running]: main.main() /main.go:25 +0x39f exit status 2 root@608d711d1786:/# ``` Even `echo 'hello' | go run main.go` fails with the same panic. I have confirmed this behavior both in a fresh container, and natively. OS: MacOS Terminal: iTerm2 Go version(s): - go version go1.14.4 darwin/amd64 - go version go1.15.6 darwin/amd64 - go version go1.15.7 darwin/amd64 - go version go1.15.7 linux/amd64
kerem closed this issue 2026-03-04 01:04:42 +03:00
Author
Owner

@rivo commented on GitHub (Feb 17, 2021):

I cannot reproduce this. I just tried it on macOS with iTerm2. I'm not sure this has something to do with tview but rather with how pipes work in your environment. Maybe you can google this error message and find out a bit more about that message? It could give us a hint of where to look.

<!-- gh-comment-id:780463325 --> @rivo commented on GitHub (Feb 17, 2021): I cannot reproduce this. I just tried it on macOS with iTerm2. I'm not sure this has something to do with `tview` but rather with how pipes work in your environment. Maybe you can google this error message and find out a bit more about that message? It could give us a hint of where to look.
Author
Owner

@tculp commented on GitHub (Feb 22, 2021):

Have you tried my steps using docker? I still get this consistently both in docker and locally. Pipes shouldn't work any differently for my environment.

This other project seemed to have a similar error: https://github.com/c-bata/go-prompt/issues/88

<!-- gh-comment-id:783441514 --> @tculp commented on GitHub (Feb 22, 2021): Have you tried my steps using docker? I still get this consistently both in docker and locally. Pipes shouldn't work any differently for my environment. This other project seemed to have a similar error: https://github.com/c-bata/go-prompt/issues/88
Author
Owner

@neezer commented on GitHub (Mar 15, 2021):

@rivo In testing out a new version as you suggested for https://github.com/rivo/tview/issues/542, I ran into this same issue.

The version before the bump does not panic with this error.

- github.com/rivo/tview v0.0.0-20201204190810-5406288b8e4e
+ github.com/rivo/tview v0.0.0-20210312174852-ae9464cc3598
<!-- gh-comment-id:799565771 --> @neezer commented on GitHub (Mar 15, 2021): @rivo In testing out a new version as you suggested for https://github.com/rivo/tview/issues/542, I ran into this same issue. The version before the bump does not panic with this error. ```diff - github.com/rivo/tview v0.0.0-20201204190810-5406288b8e4e + github.com/rivo/tview v0.0.0-20210312174852-ae9464cc3598 ```
Author
Owner

@rivo commented on GitHub (Mar 15, 2021):

I don't have Docker on my Mac so it'll take me a little bit to try this. In the meantime, could you let me know if the following program gives you the same error?

package main

import (
	"io"
	"os"
	"time"
)

func main() {
	go func() {
		if _, err := io.Copy(os.Stdout, os.Stdin); err != nil {
			panic(err)
		}
	}()
	time.Sleep(2 * time.Second)
}
ls -l --color=always | go run main.go

(I know this has appeared with newer tview versions but it's worth a shot.) It's a bit odd that there's no callstack. I also couldn't find any useful information when googling this error message.

<!-- gh-comment-id:799611453 --> @rivo commented on GitHub (Mar 15, 2021): I don't have Docker on my Mac so it'll take me a little bit to try this. In the meantime, could you let me know if the following program gives you the same error? ```go package main import ( "io" "os" "time" ) func main() { go func() { if _, err := io.Copy(os.Stdout, os.Stdin); err != nil { panic(err) } }() time.Sleep(2 * time.Second) } ``` ``` ls -l --color=always | go run main.go ``` (I know this has appeared with newer `tview` versions but it's worth a shot.) It's a bit odd that there's no callstack. I also couldn't find any useful information when googling this error message.
Author
Owner

@neezer commented on GitHub (Mar 15, 2021):

This might be relevant: https://github.com/gdamore/tcell/issues/432 (suspect because of github.com/rivo/tview@745e4ceeb7)

Running the snippet from that issue does give me the same error.


Your code snippet works fine for me (no error). FWIW I get the initial error running locally (not in Docker) in my repo.

<!-- gh-comment-id:799620660 --> @neezer commented on GitHub (Mar 15, 2021): This might be relevant: https://github.com/gdamore/tcell/issues/432 (suspect because of https://github.com/rivo/tview/commit/745e4ceeb711f2db613627be9570d4c61ee2c191) Running the snippet from that issue does give me the same error. --- Your [code snippet](https://github.com/rivo/tview/issues/556#issuecomment-799611453) works fine for me (no error). FWIW I get the initial error running locally (not in Docker) in my repo.
Author
Owner

@rivo commented on GitHub (Mar 15, 2021):

Good catch. I'm prettty sure this is the same as https://github.com/gdamore/tcell/issues/432 as I'm basically doing the same thing in tview.

<!-- gh-comment-id:799628279 --> @rivo commented on GitHub (Mar 15, 2021): Good catch. I'm prettty sure this is the same as https://github.com/gdamore/tcell/issues/432 as I'm basically doing the same thing in `tview`.
Author
Owner

@neezer commented on GitHub (Mar 15, 2021):

I'm guessing this change is the underlying cause. It fits the timeline. Given the author doesn't want to revert behavior but instead has some future plan, I'm not sure where to go from here.

What's the recourse for tview? I can reproduce @tculp 's original issue locally on macOS and inside Docker using their instructions, and my app (which operates on piped input from stdin in a similar way) is also broken.

<!-- gh-comment-id:799653509 --> @neezer commented on GitHub (Mar 15, 2021): I'm guessing [this change](https://github.com/gdamore/tcell/commit/e9095fe4f117459e3d961ea4eb3f55bf8f45e91c) is the underlying cause. It fits the timeline. Given the author [doesn't want to revert behavior but instead has some future plan](https://github.com/gdamore/tcell/pull/433#issuecomment-791180918), I'm not sure where to go from here. What's the recourse for `tview`? I can reproduce @tculp 's original issue locally on macOS and inside Docker using their instructions, and my app (which operates on piped input from stdin in a similar way) is also broken.
Author
Owner

@mevdschee commented on GitHub (Mar 16, 2021):

Like @neezer I can reproduce the issue in tview and tcell and not in the go-only example (on Ubuntu).

<!-- gh-comment-id:800008929 --> @mevdschee commented on GitHub (Mar 16, 2021): Like @neezer I can reproduce the issue in tview and tcell and not in the go-only example (on Ubuntu).
Author
Owner

@rivo commented on GitHub (Mar 16, 2021):

@neezer, I'm not sure what to do here. If tcell occupies os.Stdin, I can't work around that in tview. As soon as @gdamore lets us know how we can read input from a pipe, I'll update the Wiki example. As for your application, if there are no alternatives for you, I would suggest that you revert to a previous commit of tview for the time being. As I mention in various places (and in the README), I'm trying to keep tview backwards-compatible. So you should be able to upgrade easily once a solution has been found.

<!-- gh-comment-id:800551642 --> @rivo commented on GitHub (Mar 16, 2021): @neezer, I'm not sure what to do here. If `tcell` occupies `os.Stdin`, I can't work around that in `tview`. As soon as @gdamore lets us know how we can read input from a pipe, I'll update the Wiki example. As for your application, if there are no alternatives for you, I would suggest that you revert to a previous commit of `tview` for the time being. As I mention in various places (and in the README), I'm trying to keep `tview` backwards-compatible. So you should be able to upgrade easily once a solution has been found.
Author
Owner

@rivo commented on GitHub (Aug 2, 2021):

Is this still an issue? I can run the ANSI example on my Mac as described and it works.

If this still doesn't work for some configurations, a solution I found was to use temporary named pipes instead of relying on os.Stdin:

package main

import (
	"io"
	"os"

	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	textView := tview.NewTextView().
		SetDynamicColors(true).
		SetChangedFunc(func() {
			app.Draw()
		})
	textView.SetBorder(true).SetTitle("Stdin")
	if len(os.Args) < 2 {
		panic("Enter the file or named pipe as the first argument")
	}
	f, err := os.Open(os.Args[1])
	if err != nil {
		panic(err)
	}
	defer f.Close()
	go func() {
		w := tview.ANSIWriter(textView)
		if _, err := io.Copy(w, f); err != nil {
			panic(err)
		}
	}()
	if err := app.SetRoot(textView, true).Run(); err != nil {
		panic(err)
	}
}

Then you can do this:

go run main.go <(ls -l)

Please let me know if this issue is resolved or not. If it's not resolved, I'll update the Wiki accordingly.

<!-- gh-comment-id:890901620 --> @rivo commented on GitHub (Aug 2, 2021): Is this still an issue? I can run the ANSI example on my Mac as described and it works. If this still doesn't work for some configurations, a solution I found was to use temporary named pipes instead of relying on `os.Stdin`: ```go package main import ( "io" "os" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() textView := tview.NewTextView(). SetDynamicColors(true). SetChangedFunc(func() { app.Draw() }) textView.SetBorder(true).SetTitle("Stdin") if len(os.Args) < 2 { panic("Enter the file or named pipe as the first argument") } f, err := os.Open(os.Args[1]) if err != nil { panic(err) } defer f.Close() go func() { w := tview.ANSIWriter(textView) if _, err := io.Copy(w, f); err != nil { panic(err) } }() if err := app.SetRoot(textView, true).Run(); err != nil { panic(err) } } ``` Then you can do this: ```sh go run main.go <(ls -l) ``` Please let me know if this issue is resolved or not. If it's not resolved, I'll update the Wiki accordingly.
Author
Owner

@mevdschee commented on GitHub (Aug 2, 2021):

Is this still an issue? I can run the ANSI example on my Mac as described and it works.

I tested the latest versions of tview and tcell and this issue is resolved now. This code:

package main

import (
    "io"
    "os"

    "github.com/rivo/tview"
)

func main() {
    app := tview.NewApplication()
    textView := tview.NewTextView().
        SetDynamicColors(true).
        SetChangedFunc(func() {
            app.Draw()
        })
    textView.SetBorder(true).SetTitle("Stdin")
    go func() {
        w := tview.ANSIWriter(textView)
        if _, err := io.Copy(w, os.Stdin); err != nil {
            panic(err)
        }
    }()
    if err := app.SetRoot(textView, true).Run(); err != nil {
        panic(err)
    }
}

works now*! No need for a workaround. Versions in go.sum:

github.com/gdamore/tcell/v2 v2.3.3
github.com/rivo/tview v0.0.0-20210624165335-29d673af0ce2

Thank you for your hard work!

*) it may require tcell v2.2.1 or up (see: https://github.com/gdamore/tcell/issues/432)

<!-- gh-comment-id:890910927 --> @mevdschee commented on GitHub (Aug 2, 2021): >Is this still an issue? I can run the ANSI example on my Mac as described and it works. I tested the latest versions of tview and tcell and this issue is resolved now. This code: package main import ( "io" "os" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() textView := tview.NewTextView(). SetDynamicColors(true). SetChangedFunc(func() { app.Draw() }) textView.SetBorder(true).SetTitle("Stdin") go func() { w := tview.ANSIWriter(textView) if _, err := io.Copy(w, os.Stdin); err != nil { panic(err) } }() if err := app.SetRoot(textView, true).Run(); err != nil { panic(err) } } works now*! No need for a workaround. Versions in go.sum: github.com/gdamore/tcell/v2 v2.3.3 github.com/rivo/tview v0.0.0-20210624165335-29d673af0ce2 Thank you for your hard work! *) it may require tcell v2.2.1 or up (see: https://github.com/gdamore/tcell/issues/432)
Author
Owner

@rivo commented on GitHub (Aug 2, 2021):

Great! Thanks for the feedback.

<!-- gh-comment-id:890934097 --> @rivo commented on GitHub (Aug 2, 2021): Great! Thanks for the feedback.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#407
No description provided.