Skip to content

Add column width control and leading ellipsis truncation to Table widget #6

@StevenTCramer

Description

@StevenTCramer

Current Behavior

The `TimeWarpTerminal.WriteTable()` widget automatically truncates all columns at the end with trailing ellipsis:
```
│ Path │
│ /home/steventcramer/worktrees/github.com/TimeWa... │
```

Desired Behavior

  1. Column width control - Allow specifying max width per column (e.g., `.AddColumn("Path", maxWidth: 50)`)
  2. Leading ellipsis truncation - For long paths, show ellipsis at the BEGINNING so the END (most significant part) is visible:
    ```
    │ Path │
    │ .../timewarp-ganda/Cramer-2025-12-06-dev │
    ```

Use Case

In worktree listings, the path is important but very long. Users need to see:

  • Branch name (at the end of path)
  • Repository name
  • Just enough of the path to identify the worktree

With trailing ellipsis, all worktrees look the same because the unique part at the end is hidden.

Proposed API

```csharp
terminal.WriteTable(table =>
{
table
.AddColumn("Branch", Alignment.Left, maxWidth: 30)
.AddColumn("Repository", Alignment.Left, maxWidth: 20)
.AddColumn("Path", Alignment.Left, maxWidth: 50, truncation: Truncation.LeadingEllipsis);
});
```

Workaround Currently Used

Manually truncating strings before passing to the table:
```csharp
private static string TruncatePathLeading(string path, int maxLength)
{
if (path.Length <= maxLength) return path;
string end = path[(path.Length - maxLength + 3)..];
int sep = end.IndexOf(Path.DirectorySeparatorChar);
if (sep > 0) end = end[sep..];
return "..." + end;
}
```

This should be built into the library.

Labels

enhancement

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions