charmbracelet/bubbletea

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

cpendery opened this issue · 1 comments

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

@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.