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" />
                    
Directory.Packages.props
<PackageReference Include="FluidWidth" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=FluidWidth&version=1.1.1
                    
Install as a Cake Tool

FluidWidth πŸ“

Advanced Terminal-Aware String Display Width Calculator

Cross-Platform Terminal-Aware String Display Width Calculator

License: Proprietary

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 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