Returns what the character width should be on the terminal.
Perl6
Latest commit bb88164 Jan 29, 2017 @bluebear94 committed on GitHub Merge pull request #3 from paultcochrane/pr/add-travis-config
Add Travis-CI configuration
Permalink
Failed to load latest commit information.
lib/Terminal Add a proper synopsis Nov 17, 2015
t Initial commit Nov 16, 2015
.travis.yml Add Travis-CI configuration Nov 12, 2016
LICENSE Initial commit Nov 16, 2015
META.info Add mandatory "perl" META field Oct 26, 2016
README.md Fix typo in docs Nov 16, 2015

README.md

Terminal::WCWidth

A Perl 6 port of this module.

Usage

wcwidth takes a single codepoint and outputs its width:

wcwidth(0x3042) # "あ" - returns 2

Returns:

  • -1 for a control character
  • 0 for a character that does not advance the cursor (NULL or combining)
  • 1 for most characters
  • 2 for full width characters

wcswidth takes a string and outputs its total width:

wcswidth("*ウルヰ*") # returns 8 = 2 + 6

Returns -1 if any control characters are found.

Unlike the Python version, this module does not support getting the width of only the first n characters of a string, as you can use the substr method.

Acknowledgements

Thanks to Jeff Quast (jquast), the author of the Python module, which in turn is based on the C library by Markus Kuhn.