bubbletea icon indicating copy to clipboard operation
bubbletea copied to clipboard

v2: window title should be cleared (or reset) on shutdown

Open lrstanley opened this issue 4 months ago • 3 comments

Describe the bug

If the app panics and needs recovering, or even in normal exiting state, the window title stays as it was set by bubbletea after bubbletea exits, leaving the terminal in a different state than before the app was started.

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

  • OS: ubuntu (wsl2)
  • Shell: bash
  • Terminal Emulator: Windows Terminal
  • Terminal Multiplexer: n/a

Expected behavior

I am not 100% sure what is available through OSC, but one of these would be ideal:

  1. "restore" the title (looks like it may be available in OSC, if I'm reading right?)
  2. Query the current title, before the app can explicitly set a title, store that, then re-set it post-tea.Quit and similar recovery scenarios.
  3. Worst-case scenario, set title to "", which at least in some terminals will revert the title back to its original state (does with Windows Terminal).

lrstanley avatar Aug 17 '25 09:08 lrstanley

Hi @lrstanley,

Most programs and shells use OSC 0, OSC 1, or OSC 2 to change the window's title. OSC 2 is probably the most compatible, since it's introduced in DEC VT520. These commands only set the window/icon and there's no way we can query the window title with these commands. However, as mentioned, we could reset the title to an empty string "" before exiting.

aymanbagabas avatar Sep 05 '25 15:09 aymanbagabas

Hi @aymanbagabas,

I would love to submit a fix.

My proposed approach would be to locate the program's shutdown logic in tea.go. I believe the best place for the fix is within the defer block in the (p *Program) start() function. I'll add a call to p.renderer.SetWindowTitle("") there to ensure the title is cleared just before the renderer stops.

Let me know if that sounds good!

Thanks!

devvaansh avatar Oct 02 '25 14:10 devvaansh

Hi @devvaansh, thank you for bringing this up. We have a fix that's part of the new declarative API here, specifically here.

aymanbagabas avatar Oct 14 '25 20:10 aymanbagabas