Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bubbletea's alt screen isn't triggering when run as a bash subcommand #823

Open
cpendery opened this issue Sep 14, 2023 · 1 comment
Open

Comments

@cpendery
Copy link

Describe the bug
I'm trying to run a bubbletea app as a bash subcommand where all the UI gets sent to an alt window that the user interacts with and when the app closes I can write some data to stdout and capture it. Basically the script would look like output=$(./fullscreen). When I try this with the fullscreen example, it just hangs for 5 seconds without displaying the alt screen. Is this possible to do with bubbletea's implementation? I know it can be done with tcell, and I'm getting back the escape code \E[?25l\E[?1049h\E[2J\E[1;1H\E[1;1H\E[?25l\r.

Setup
Please complete the following information along with version numbers, if applicable.

  • OS: windows
  • Shell: bash
  • Terminal Emulator: git bash

To Reproduce
Steps to reproduce the behavior:

  1. Build the fullscreen example
  2. Run $(./fullscreen)
  3. Observe that the UI isn't shown
  4. Receive error after 5 seconds about escape string \E[?25l\E[?1049h\E[2J\E[1;1H\E[1;1H\E[?25l\r

Source Code
N/A

Expected behavior
I'd think the alternate screen would show for the 5 seconds and then the command would terminate

Screenshots
N/A

Additional context
N/A

@wolfmagnate
Copy link

@cpendery
Currently, bubble tea programs are not supposed to redirect their output results to another file or pipe them to a command. Therefore, for example, if you write bubbles tea's standard output to a file with the current implementation, the file will have ANSI control characters written directly to it.

As shown in the example in /examples/pipe, bubble tea will automatically create a new terminal by opening a new "dev/tty" and input from the terminal if it determines that input is given from a non-terminal source at startup. However, it does not seem to judge whether the output is other than terminal or not at startup. This is why the fmt.Fprint(o.tty, CSI+AltScreenSeq) part of termenv's AltScreen() internal process, which is executed internally, is not interpreted by the terminal and does not result in an alt screen. (Actually, the [?1049 in the escape string you received is a special instruction string to the terminal, representing the command to show alt screen.)

I have no workaround for this problem in bubble tea at this time, and I guess that a new feature needs to be implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants