Skip to content

TextWidget

Display static or dynamic text content in your terminal UI.

Basic Usage

Create a simple text display using the fluent API:

csharp
using Hex1b;

await using var terminal = Hex1bTerminal.CreateBuilder()
    .WithHex1bApp((app, options) => ctx => ctx.VStack(v => [
        v.Text("Welcome to Hex1b"),
        v.Text("Build beautiful terminal UIs")
    ]))
    .Build();

await terminal.RunAsync();

Text Overflow Behavior

TextWidget provides three modes for handling text that exceeds the available width:

csharp
using Hex1b;

await using var terminal = Hex1bTerminal.CreateBuilder()
    .WithHex1bApp((app, options) => ctx => ctx.VStack(v => [
        v.Text("═══ Text Overflow Modes ═══"),
        v.Text(""),
        v.Text("Wrap Mode:"),
        v.Text(
            "This is a long description that demonstrates text wrapping behavior in Hex1b. " +
            "When the text content exceeds the available width of the container, it automatically " +
            "breaks at word boundaries to fit within the allocated space. This ensures that all " +
            "content remains visible to the user without requiring horizontal scrolling. The widget's " +
            "measured height increases dynamically based on the number of wrapped lines."
        ).Wrap(),
        v.Text(""),
        v.Text("Ellipsis Mode:"),
        v.Text(
            "This is a much longer piece of text that will definitely " +
            "be truncated with an ellipsis character sequence when it " +
            "exceeds the available fixed width of forty columns"
        ).Ellipsis().FixedWidth(40),
        v.Text(""),
        v.Text("Default (Truncate) Mode:"),
        v.Text(
            "This text extends beyond its allocated bounds and " +
            "will be clipped by the parent container if clipping is enabled"
        )
    ]))
    .Build();

await terminal.RunAsync();

Truncate (Default)

Text is clipped when it extends beyond its bounds. No visual indicator is shown:

csharp

Wrap

Text wraps to multiple lines at word boundaries:

csharp

When wrapping:

  • Words break at spaces when possible
  • Very long words are broken mid-word if necessary
  • The widget's measured height increases with the number of lines

Ellipsis

Text is truncated with "..." when it exceeds the width:

csharp

Unicode Support

TextWidget correctly handles Unicode text including:

  • Wide characters (CJK): 日本語, 中文, 한국어
  • Emoji: 🎉 🚀 ✨
  • Combining characters: é, ñ
  • Box-drawing characters: ┌─┐│└─┘
csharp

Released under the MIT License.