{
  "id": "josverl/mp_wcwidth",
  "name": "mp_wcwidth",
  "prettyName": "mp_wcwidth",
  "description": "A simplified version of wcwidth optimized for MicroPython and embedded systems.",
  "version": "",
  "author": "josverl",
  "license": "NOASSERTION",
  "tags": [
    "micropython",
    "unicode"
  ],
  "status": "VALID",
  "official": false,
  "source": "https://github.com/josverl/mp_wcwidth",
  "updatedAt": "2026-09-29T07:00:23.514Z",
  "page": "https://checkmim.com/packages/josverl+mp_wcwidth",
  "createdAt": "2026-01-21T20:30:29.657Z",
  "submittedBy": "Jos Verlinde",
  "install": {
    "mpremote": "mpremote mip install github:josverl/mp_wcwidth",
    "mip": "import mip; mip.install(\"github:josverl/mp_wcwidth\")"
  },
  "readme": "# wcwidth - Simplified wcwidth for MicroPython\n\nThis is a simplified version of [wcwidth](https://github.com/jquast/wcwidth) optimized for MicroPython and embedded systems.\n\n## Size Comparison\n\n| Version | Lines of Code | Disk Size | Unicode Versions |\n|---------|---------------|-----------|------------------|\n| **MicroPython  wcwidth** | 746 | 88 KB | 1 version (17.0.0 only) |\n| **Original wcwidth** | 7,888 | 672 KB | 21 versions (4.1.0 - 17.0.0) |\n\n**Size reduction: ~90% (from 672 KB to 88 KB)**\n\n## What's Removed\n\n- Multi-version support (only Unicode 17.0.0 is included)\n- Version selection logic and environment variable handling\n- Standard library `functools.lru_cache` (replaced with simple dict-based cache)\n- VS15 table (not commonly used)\n- Warnings and detailed error messages\n- lru_cache replace by simplistic cache implementation\n  \n## What's Kept\n\n- Full Unicode 17.0.0 character width tables\n- `wcwidth()` - character width measurement\n- `wcswidth()` - string width measurement  \n- Support for:\n  - Wide characters (CJK, emoji, etc.)\n  - Zero-width characters (combining marks, ZWJ, etc.)\n  - VS16 (Variation Selector 16) for emoji modifiers\n  - Control character detection\n\n## Installation\n\nSimplest way to install the module on your MicroPython board is via `mpremote mip`:\n\n```\nmpremote mip install github:josverl/mp_wcwidth\n```\n\n## Usage\n\n```python\nfrom wcwidth import wcwidth, wcswidth\n\n# Get width of a single character\nprint(wcwidth('A'))      # 1 (normal ASCII)\nprint(wcwidth('你'))     # 2 (wide CJK character)\nprint(wcwidth('🪲'))     # 2 (wide emoji)\nprint(wcwidth('\\u0301')) # 0 (combining accent)\nprint(wcwidth('\\n'))     # -1 (control character)\n\n# Get width of a string\nprint(wcswidth('Hello'))         # 5\nprint(wcswidth('你好'))           # 4\nprint(wcswidth('print(\"🪲\")'))   # 11\n```\n\n## Demo\nA simple demo script `demo.py` is included to showcase the functionality:\n\n```bash \n# Install the module and demo script to your MicroPython device\nmpremote mip install github:josverl/mp_wcwidth\nmpremote mip install --target . github:josverl/mp_wcwidth/demo.py\n\n# Run the demo on the device \nmpremote exec \"exec(open('demo.py').read())\"\n```\n\n\n## Caching\n\nThe simplified version includes a minimal cache implementation (`simple_cache.py`) that replaces Python's `functools.lru_cache`:\n\n- **Fixed size**: Uses a simple dict with size limit (no reallocation)\n- **FIFO eviction**: When full, clears entire cache (ultra-simple)\n- **No external dependencies**: Pure Python, MicroPython compatible\n- **Minimal overhead**: ~90 lines of code\n- **Default cache size**: 128 entries for `wcwidth()`\n\nThe cache significantly improves performance for repeated character width lookups.\n\n## Testing\n\nAll basic functionality works identically to the original:\n\n```bash\npython -c \"import wcwidth; print(wcwidth.wcwidth('🪲'))\"  # 2\n\nmpremote exec \"import wcwidth; print(wcwidth.wcwidth('🪲'))\"  # 2\n```\n\n## License\n\nSame as original wcwidth (MIT License)\n\n## Credits\n\nBased on [wcwidth](https://github.com/jquast/wcwidth) by Jeff Quast, which is based on Markus Kuhn's wcwidth.c implementation.\n"
}