[GH-ISSUE #785] STDIN of tview process skipping some characters #575

Closed
opened 2026-03-04 01:06:10 +03:00 by kerem · 2 comments
Owner

Originally created by @sharadregoti on GitHub (Dec 21, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/785

I have the following program, which tries to get a shell access into a running kubernetes pod. I am trying to achieve the same functionality but using tview. With below program i am able sync stdout, stdin, stderr of the kubectl process with tview UI.

But while inputting something (as it is a shell). I have to press the same key multiple times to view it on the UI.

package main

import (
	"fmt"
	"os"
	"os/exec"
	"time"

	"github.com/rivo/tview"
)

func main() {
	arr := []string{"exec", "-it", "-n", "db", "postgres-dev-6844b6cb77-hqh9r", "--", "bash"}
	cc := exec.Command("kubectl", arr...)

	app := tview.NewApplication()

	textArea := tview.NewTextView()

	cc.Stdin = os.Stdin
	cc.Stdout = os.Stdout
	cc.Stderr = os.Stderr

	if err := cc.Start(); err != nil {
		fmt.Println("failed to start", err)
		return
	}

	go func() {
		if err := cc.Wait(); err != nil {
			fmt.Println("failed to wait", err)
			return
		}
	}()

	if err := app.SetRoot(textArea,
		true).EnableMouse(false).Run(); err != nil {
		panic(err)
	}
}

image

For example, In this image I had to press l 2 times, s 2 times & enter key 2 times to execute the ls command. And also i am not able to view the cursor of shell.

What am I doing wrong here?

Originally created by @sharadregoti on GitHub (Dec 21, 2022). Original GitHub issue: https://github.com/rivo/tview/issues/785 I have the following program, which tries to get a shell access into a running kubernetes pod. I am trying to achieve the same functionality but using tview. With below program i am able sync stdout, stdin, stderr of the kubectl process with tview UI. But while inputting something (as it is a shell). I have to press the same key multiple times to view it on the UI. ``` package main import ( "fmt" "os" "os/exec" "time" "github.com/rivo/tview" ) func main() { arr := []string{"exec", "-it", "-n", "db", "postgres-dev-6844b6cb77-hqh9r", "--", "bash"} cc := exec.Command("kubectl", arr...) app := tview.NewApplication() textArea := tview.NewTextView() cc.Stdin = os.Stdin cc.Stdout = os.Stdout cc.Stderr = os.Stderr if err := cc.Start(); err != nil { fmt.Println("failed to start", err) return } go func() { if err := cc.Wait(); err != nil { fmt.Println("failed to wait", err) return } }() if err := app.SetRoot(textArea, true).EnableMouse(false).Run(); err != nil { panic(err) } } ``` ![image](https://user-images.githubusercontent.com/24411676/208962940-bbacf137-5765-403f-8604-2f814967b67b.png) For example, In this image I had to press `l` 2 times, `s` 2 times & `enter` key 2 times to execute the ls command. And also i am not able to view the cursor of shell. What am I doing wrong here?
kerem closed this issue 2026-03-04 01:06:10 +03:00
Author
Owner

@sharadregoti commented on GitHub (Jan 2, 2023):

@rivo Any update on this?

<!-- gh-comment-id:1369107261 --> @sharadregoti commented on GitHub (Jan 2, 2023): @rivo Any update on this?
Author
Owner

@rivo commented on GitHub (Jan 2, 2023):

I'm not able to run this program as it requires external dependencies.

But in any case, I don't think assigning os.Stdin/os.Stdout to other processes will work with tview (or tcell, for that matter). tcell needs these two for itself. So whatever the problem is here, it's very likely due to two different processes trying to access the same resource.

<!-- gh-comment-id:1369114716 --> @rivo commented on GitHub (Jan 2, 2023): I'm not able to run this program as it requires external dependencies. But in any case, I don't think assigning `os.Stdin`/`os.Stdout` to other processes will work with `tview` (or `tcell`, for that matter). `tcell` needs these two for itself. So whatever the problem is here, it's very likely due to two different processes trying to access the same resource.
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#575
No description provided.