Skip to content

Add Textual TUI #2462

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Add Textual TUI #2462

wants to merge 9 commits into from

Conversation

willmcgugan
Copy link

This adds a Textual TUI for CLAI.

This has more or less feature parity with the existing TUI.

There is probably a little more work to do for error handling. And tools aren't yet implemented. Consider this a foundation to build upon.

@benomahony
Copy link

This looks amazing! Very excited to see it land!

@samuelcolvin
Copy link
Member

Hi @willmcgugan, before we proceed, there's a few fundamental things I want to make sure we're aligned on.

  • I'm using the default MacOS terminal, this seems to change the background and foreground colors in the terminal, is this avoidable? I can choose a better theme than the default one, but Ideally I wouldn't need to choose a theme at all, if we do need these themes, they need to persist
  • Do TUI apps have to take over the entire terminal?
  • exiting this version of clai seems a bit more complicated than the current one, can that be solved?
  • in my terminal, copy and paste within the TUI doesn't seem to work the same as in the normal terminal, is this solvable?
image

@willmcgugan
Copy link
Author

  • I'm using the default MacOS terminal, this seems to change the background and foreground colors in the terminal, is this avoidable? I can choose a better theme than the default one, but Ideally I wouldn't need to choose a theme at all, if we do need these themes, they need to persist

The default MacOS terminal is old, slow, and limited to 256 colors (which is why it looks bad). All other terminal support 16.7 million colors and have done for years. I could encourage you to switch to iTerm2, Kitty, wezterm, or Ghostty which are miles better and actively developed.

It wouldn't be difficult to pick a default theme that looks better in 256 colors, and save it as a setting.

Or you could wait for the forthcoming macOS Tahoe this year, which should finally have an update to the terminal.

  • Do TUI apps have to take over the entire terminal?

I suspect you are alluding to it working the way Rich live works, by updating the scrollback buffer. Doing it that way is slow and prone to flicker. You also can't copy without also copying hard line breaks and other non-text characters. If you want a half decent UX then the TUI needs to use the "alternate buffer", which allows the app to manage the "screen".

  • exiting this version of clai seems a bit more complicated than the current one, can that be solved?

ctrl+q to quit. You could add that to the footer.

  • in my terminal, copy and paste within the TUI doesn't seem to work the same as in the normal terminal, is this solvable?

macOS terminal doesn't support the copy to clipboard extension. Virtually all other terminals you can use ctrl+C to copy.

@willmcgugan
Copy link
Author

You can use ansi colors (i.e. the color theme you set in your terminal), by setting ansi_color=True on the app constructor, and tweaking the CSS. However, it will look objectively bad compared to the Textual themes.

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

Successfully merging this pull request may close these issues.

4 participants