Advice writing new TUI applications #8969

Open
opened 2026-01-31 01:42:43 +00:00 by claunia · 0 comments
Owner

Originally created by @rksouthee on GitHub (Jun 11, 2020).

I'm interested in writing a TUI application for the Windows Console. Following
the advice from Rich Turner I thought that this might be a good opportunity
to use the new Virtual Terminal Sequences.

For performance reasons, I need to maintain two screen buffers (one representing
the current state of the screen, and the desired state). I believe I have the
following options available to me (possibly more) for storing the state (I'm
ignoring colour):

  1. Use char32_t. This gives me full unicode support and constant time lookup
    but I have to go through another conversion before I call WriteConsole (is
    it better to call WriteConsoleW, or WriteConsoleA using UTF-8?). I need
    to write the converions between unicode and utf8 (or better use a library).

  2. Use char16_t or wchar_t. I can convert using MultiByteToWideChar and
    write to the console using WriteConsoleW. I get more help from Windows but
    I miss out on full Unicode support.

  3. Use utf8. I lose constant time lookup, but I can write to the console using
    WriteConsoleA and I don't need to worry about conversions.

  4. Use an architecture similar to the internals of the Windows Console.
    This doesn't seem desirable, I shouldn't be concerning myself with the
    internal implementation.

  5. Use the Windows Console API, I have access to the screen state with
    ReadConsoleOutput, I only need to concern myself with the desired state of
    the screen. I don't get full Unicode support but I'm integrating smoothly
    with Windows.

Although my original intent was to use the new Virtual Terminal Sequences, it
seems for my particular application that the Console API would be suitable.

Any advice with regards to writing new TUI applications would be much
appreciated or if this is a design decision application writers need to make.

Originally created by @rksouthee on GitHub (Jun 11, 2020). I'm interested in writing a TUI application for the Windows Console. Following the advice from [Rich Turner][1] I thought that this might be a good opportunity to use the new Virtual Terminal Sequences. For performance reasons, I need to maintain two screen buffers (one representing the current state of the screen, and the desired state). I believe I have the following options available to me (possibly more) for storing the state (I'm ignoring colour): 1. Use `char32_t`. This gives me full unicode support and constant time lookup but I have to go through another conversion before I call `WriteConsole` (is it better to call `WriteConsoleW`, or `WriteConsoleA` using UTF-8?). I need to write the converions between unicode and utf8 (or better use a library). 2. Use `char16_t` or `wchar_t`. I can convert using `MultiByteToWideChar` and write to the console using `WriteConsoleW`. I get more help from Windows but I miss out on full Unicode support. 3. Use utf8. I lose constant time lookup, but I can write to the console using `WriteConsoleA` and I don't need to worry about conversions. 4. Use an architecture similar to the [internals][2] of the Windows Console. This doesn't seem desirable, I shouldn't be concerning myself with the internal implementation. 5. Use the Windows Console API, I have access to the screen state with `ReadConsoleOutput`, I only need to concern myself with the desired state of the screen. I don't get full Unicode support but I'm integrating smoothly with Windows. Although my original intent was to use the new Virtual Terminal Sequences, it seems for my particular application that the Console API would be suitable. Any advice with regards to writing new TUI applications would be much appreciated or if this is a design decision application writers need to make. [1]: https://devblogs.microsoft.com/commandline/new-experimental-console-features/ [2]: https://devblogs.microsoft.com/commandline/windows-command-line-unicode-and-utf-8-output-text-buffer/
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 01:42:43 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8969