FluidWidth 1.1.1
dotnet add package FluidWidth --version 1.1.1
NuGet\Install-Package FluidWidth -Version 1.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluidWidth" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluidWidth" Version="1.1.1" />
<PackageReference Include="FluidWidth" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FluidWidth --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FluidWidth, 1.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FluidWidth@1.1.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FluidWidth&version=1.1.1
#tool nuget:?package=FluidWidth&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FluidWidth π
Advanced Terminal-Aware String Display Width Calculator
Cross-Platform Terminal-Aware String Display Width Calculator
Professional-grade library for accurate string width calculation in terminal/console applications with full Unicode support.
β¨ Features
- β ANSI Escape Codes - Automatically stripped, width calculated correctly
- β Emoji & ZWJ Sequences - π¨βπ©βπ§βπ¦, π©ββοΈ, πβπ¦Ί, β€οΈβπ₯, with VS15/VS16 support
- β East Asian Characters - δΈζ, ζ₯ζ¬θͺ, νκ΅μ΄ with proper width (Fullwidth/Halfwidth)
- β Unicode Grapheme Clusters - Correct handling of combined characters
- β Tab Characters - Configurable tab stops
- β Zero-Width Characters - Proper detection and exclusion
- β Performance Optimized - LRU caching, fast paths for ASCII
- β Strongly Named Assembly - Ready for enterprise deployment
- β No External Dependencies - Self-contained
π Cross-Platform Support
FluidWidth works seamlessly on all major platforms:
π Quick Start
using FluidWidth.Public;
// Calculate display width with emoji
int width = AnsiHelper.GetDisplayWidth("Hello π¨βπ©βπ§βπ¦ World!");
// Returns: 14 cells
// Strip ANSI escape codes
string clean = AnsiHelper.StripAnsiCodes("\x1B[31mRed\x1B[0m Text");
// Returns: "Red Text"
// Configure
AnsiHelper.EmojiWidthMode = EmojiWidthMode.ModernTerminal;
π― Basic Examples
// Various text examples
string[] texts = {
"ASCII Only", // 10 cells
"With emoji π", // 13 cells
"With flag πΊπΈ", // 12 cells
"With skin tone ππ»", // 17 cells
"Japanese ζ₯ζ¬θͺ", // 15 cells
"Keycap #οΈβ£", // 9 cells
"Heart β€οΈ", // 8 cells
"Family π¨βπ©βπ§βπ¦" // 8 cells
};
foreach (string text in texts)
{
int width = AnsiHelper.GetDisplayWidth(text);
Console.WriteLine($"'{text}' β {width} cells");
}
βοΈ Configuration
// Emoji Width Modes
AnsiHelper.EmojiWidthMode = EmojiWidthMode.Conservative; // All emoji = 2 cells
AnsiHelper.EmojiWidthMode = EmojiWidthMode.ModernTerminal; // ZWJ sequences = 1 cell (Default)
AnsiHelper.EmojiWidthMode = EmojiWidthMode.TextPresentation; // Respect VS15/VS16
// East Asian Support
AnsiHelper.UseEastAsianFullwidth = true; // Treat East Asian chars as 2 cells
π Advanced Usage
1. Progress Bars
public static string CreateProgressBar(int totalWidth, double percentage, string label = "")
{
int barWidth = totalWidth - 10;
int filled = (int)(barWidth * percentage);
string bar = new string('β', filled);
string empty = new string('β', barWidth - filled);
return $"[{bar}{empty}] {(percentage * 100):F1}% {label}";
}
// Output: [ββββββββββββββββββββββββββββββββββββββββββββ] 75.0% Loading
2. Text Alignment
string[] items = { "Apple", "Banana π", "Orange π" };
int columnWidth = 20;
foreach (string item in items)
{
int itemWidth = AnsiHelper.GetDisplayWidth(item);
int padding = columnWidth - itemWidth;
string aligned = item + new string(' ', padding) + "|";
Console.WriteLine($"|{aligned}");
}
3. Text Truncation
public static string TruncateToWidth(string text, int maxWidth, string ellipsis = "β¦")
{
int textWidth = AnsiHelper.GetDisplayWidth(text);
if (textWidth <= maxWidth) return text;
int ellipsisWidth = AnsiHelper.GetDisplayWidth(ellipsis);
int targetWidth = maxWidth - ellipsisWidth;
StringBuilder result = new StringBuilder();
int currentWidth = 0;
foreach (char c in text)
{
string charStr = c.ToString();
int charWidth = AnsiHelper.GetDisplayWidth(charStr);
if (currentWidth + charWidth > targetWidth)
break;
result.Append(charStr);
currentWidth += charWidth;
}
return result.ToString() + ellipsis;
}
// Usage
string truncated = TruncateToWidth("Long text with emoji π¨βπ©βπ§βπ¦", 30);
// Returns: "Long text with emojiβ¦"
π Test Output Example
=== FluidWidth Library Test ===
1. QUICK START TESTS
π Text: 'Hello π¨βπ©βπ§βπ¦ World!'
Width: 14 cells
π¨ ANSI Text: 'β[31mRedβ[0m and β[32mGreenβ[0m'
Clean: 'Red and Green'
Width: 13 cells
2. BASIC EXAMPLES
π Text Width Calculations:
'ASCII Only' β 10 cells
'With emoji π' β 13 cells
'With flag πΊπΈ' β 12 cells
'With skin tone ππ»' β 17 cells
'Japanese ζ₯ζ¬θͺ' β 15 cells
'Keycap #οΈβ£' β 9 cells
'Heart β€οΈ' β 8 cells
'Family π¨βπ©βπ§βπ¦' β 8 cells
3. CONFIGURATION TESTS
Testing EmojiWidthMode for π¨βπ©βπ§βπ¦:
Conservative: 2 cells
ModernTerminal: 1 cells
TextPresentation: 1 cells
4. COMMON USE CASES
π Progress Bar Example:
[βββββββββββββββββββββββ] 0%
[βββββββββββββββββββββββ] 25%
[βββββββββββββββββββββββ] 50%
[βββββββββββββββββββββββ] 75%
[βββββββββββββββββββββββ] 100%
π Text Alignment Example:
|Apple |
|Banana π |
|Orange π |
|Grapes π |
βοΈ Text Truncation Example:
Original: 'This is a very long text with emoji π¨βπ©βπ§βπ¦...'
Width: 65 cells
Truncated: 'This is a very long text withβ¦'
Truncated Width: 30 cells
Installation
dotnet add package FluidWidth
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.1 | 102 | 1/17/2026 |