mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #645] Is there a way to make a box a "terminal view" ? #470
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#470
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @khepin on GitHub (Sep 13, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/645
I was trying to create a UI that would look something like:
Where the top box is just information about detecting local file changes and syncing those upstream and the bottom one is a bash terminal / ssh session to said upstream. Something where the bottom window could receive an
stdin, stderr, stdout.At first glance I don't see a way to make something like this happen. Am I missing something?
@rgrannell1 commented on GitHub (Sep 14, 2021):
I believe this is possible, I'm doing something similar:
github.com/rgrannell1/rl@f24ac01815/process.go (L45)TextViewto hold terminal stderr, stdout outputexec.Cmd, and redirect output to the TextView component writer/dev/ttyand handling / passing keystrokes throughSorry about the vague answer, but I hope it helps
@khepin commented on GitHub (Sep 14, 2021):
Yup, stdout, stderr I got alright indeed. The sticky part seems to be
@rgrannell1 commented on GitHub (Sep 14, 2021):
I figured; I would have been more exact if this was something I'd implemented (note I'm a user, not the package dev). My well-commented CLI RL does most of what you're trying, so it might be a useful reference. It:
SetInputCaptureandSetDoneFuncand anInputFieldto capture user-entered textprocess.go:StartCommand)based on TUI state and user-input, and intercepts output. It pipesstdoutto a TextViewerWhat I see as difficult in your case is working around
Pseudo-terminal will not be allocated because stdin is not a terminalHowever you can force TTY use using
ssh -tt <ip>which works for RL. SSH accepts commands fromstdinsoRun from
exec.Cmdwill achieve what you want. For example, when I run this command from RL it SSH's into mymultipassVM, runs commands like list (awkwardly, rl is not an SSH client really) and returns standard-output (only, RL handles stderr badly at the moment) to a textview component. It even renderscatimgimages correctly!I hope this helps, reach out via this ticket (if the package-owner doesn't object) and I'll try to help
@khepin commented on GitHub (Sep 14, 2021):
I think I was able to approach my goal using https://github.com/creack/pty
But capturing STDIN and io.Copy-ing it to a TextView seems to suffer from a lot of performance drag and characters are missed out entirely. The same code outside of a TextView, using a buffer or stdout as the place to write works "just fine™".
If I could figure out the perf issue there, then the remaining piece would be figuring out how control sequences are sent. That doesn't seem to work with the PTY based solution I tried so far.
@khepin commented on GitHub (Sep 14, 2021):
Also, thanks, I'll dig into
SetInputCaptureand your CLI today if I can.@rgrannell1 commented on GitHub (Sep 14, 2021):
one gotcha I spent a lot of time root-causing. When commands are run non-interactively, they may buffer output and not work as expected (for me, grep would not output). You may need to use the
stdbufandunbuffershell commands (or a Golang equivalent) if you run into similar issues@rivo commented on GitHub (Sep 26, 2021):
@khepin You'll definitely get a performance hit. Characters from the external application will be stored in a buffer, that buffer will be formatted to fit the
TextView, the resulting characters will be saved to atcellscreen buffer, andtcellwill then output Escape sequences to your terminal. If you useANSIWriter, e.g. for coloured output, then there is even one more step.But that's just due to the architecture of the whole project. There's no way to bypass this (except by suspending the application temporarily). What you can do, however, is to space out your
TextViewredraws so the steps above don't happen after each character sent by your application.@khepin commented on GitHub (Sep 27, 2021):
Yup, this was using an ANSIWriter. I'll see if I can give a shot at spacing the
TextViewredraws a bit more and if that helps enough.@tedsmitt commented on GitHub (Oct 27, 2022):
@khepin did you ever find a solution to this? Would like to achieve the same functionality!
@khepin commented on GitHub (Oct 27, 2022):
Nope, I stopped working on what I needed it for too so I don't have much to offer.