bubbletea icon indicating copy to clipboard operation
bubbletea copied to clipboard

Tea and termenv do not honor WithOutput properly

Open knz opened this issue 3 years ago • 3 comments

There's a mismatch in API semantics:

  • termenv relies on the output going to os.Stdout
  • bubbletea makes this configurable (via WithOutput)

When bubbletea WithOutput is used with a different file, termenv does not recognize color profiles properly any more.

Generally, the mistake being made is the assumption that stdout is the file descriptor connected to the terminal. generally, the terminal is to be found on stdin, not stdout (and neither stderr!)

This mismatch is the cause of the following issues:

  • https://github.com/charmbracelet/bubbletea/issues/172
  • https://github.com/charmbracelet/bubbletea/issues/206
  • https://github.com/charmbracelet/bubbletea/issues/302
  • https://github.com/charmbracelet/bubbletea/discussions/386

I understand that the "next generation termenv" at https://github.com/muesli/termenv/tree/termenv-next would help with this, but I don't seem to see a timeline to get this moving forward?

knz avatar Aug 25 '22 16:08 knz

FWIW, BSD libedit and readline treat the input and output file descriptors separately:

  • the input raw mode is set on the input file descriptor
  • the output escape codes, incl term initialization etc are sent on the output file descriptor

knz avatar Aug 25 '22 16:08 knz

Oh and both query the terminal size using ioctl / TIOCGWINSZ on the input file desc, not output. Unsure why.

knz avatar Aug 25 '22 16:08 knz

Yep, the termenv-next branch of termenv, as well as the termenv-output branch of bubbletea and the next branch of lipgloss address this issue. No timeline, but it's one of the things I'm currently working on.

muesli avatar Aug 25 '22 16:08 muesli

Oh and both query the terminal size using ioctl / TIOCGWINSZ on the input file desc, not output. Unsure why.

We should look into that, I see more apps doing that.

muesli avatar Sep 27 '22 01:09 muesli