Skip to content

Terminal state not fully cleaned up on application exit #44

@Aaronontheweb

Description

@Aaronontheweb

Problem

When a Termina application exits, the terminal can be left with visual artifacts or in an inconsistent state. The host application has to manually reset terminal state after Termina shuts down.

Current Workaround

We had to add manual terminal reset code in our application:

private static void ResetTerminal()
{
    try
    {
        // ANSI escape sequences to reset terminal state:
        // \x1b[?25h - Show cursor
        // \x1b[0m - Reset all attributes
        Console.Write("\x1b[?25h\x1b[0m");

        // Clear any partial line artifacts
        Console.WriteLine();

        // Reset console properties
        Console.ResetColor();
        if (!Console.IsOutputRedirected)
        {
            Console.CursorVisible = true;
        }
    }
    catch
    {
        // Ignore any errors during terminal reset
    }
}

This is called after host.StopAsync() completes.

Expected Behavior

Termina should automatically:

  1. Exit alternate screen buffer (\x1b[?1049l) if it was entered
  2. Show cursor (\x1b[?25h)
  3. Reset all text attributes (\x1b[0m)
  4. Reset colors to terminal defaults
  5. Clear any partial rendering artifacts

This cleanup should happen in the TerminaHostedService.StopAsync() or equivalent shutdown path.

Environment

  • Linux terminal (also likely affects macOS Terminal, iTerm2, Windows Terminal)
  • Termina 0.1.x via AddTermina() hosting extension

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions