CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-tabulate

Pretty-print tabular data in Python with extensive formatting options and output format support.

Overall
score

69%

Overview
Eval results
Files

task.mdevals/scenario-8/

Text Width Calculator

A utility that calculates the display width of text strings, accounting for wide characters and whitespace handling preferences.

Capabilities

Calculate visible width for regular text

  • Given the string "Hello World", the width calculator returns 11 @test
  • Given an empty string "", the width calculator returns 0 @test

Calculate visible width for text containing wide characters

  • Given the string "中文", the width calculator returns 4 when wide character support is enabled @test
  • Given the string "Hello世界", the width calculator returns 9 when wide character support is enabled (5 for "Hello" + 4 for "世界") @test

Handle whitespace based on configuration

  • Given the string " text " with whitespace preservation disabled, the width calculator returns 4 (whitespace stripped) @test
  • Given the string " text " with whitespace preservation enabled, the width calculator returns 8 (all characters counted) @test

Toggle configuration settings

  • The wide character mode can be enabled and disabled, affecting subsequent width calculations @test
  • The whitespace preservation mode can be enabled and disabled, affecting subsequent width calculations @test

Implementation

@generates

API

def calculate_width(text: str) -> int:
    """
    Calculate the display width of text based on current module configuration.

    Args:
        text: The text string to measure

    Returns:
        The calculated display width as an integer
    """
    pass

def set_wide_chars_mode(enabled: bool) -> None:
    """
    Configure whether wide characters (CJK) should be counted with double width.

    Args:
        enabled: True to enable wide character support, False to disable
    """
    pass

def set_preserve_whitespace(enabled: bool) -> None:
    """
    Configure whether leading and trailing whitespace should be preserved in calculations.

    Args:
        enabled: True to preserve whitespace, False to strip it
    """
    pass

def get_wide_chars_mode() -> bool:
    """
    Get the current wide character mode setting.

    Returns:
        True if wide character support is enabled, False otherwise
    """
    pass

def get_preserve_whitespace() -> bool:
    """
    Get the current whitespace preservation setting.

    Returns:
        True if whitespace preservation is enabled, False otherwise
    """
    pass

Dependencies { .dependencies }

tabulate { .dependency }

Provides table formatting with configurable module-level settings for wide character support and whitespace handling.

Install with Tessl CLI

npx tessl i tessl/pypi-tabulate

tile.json