https://github.com/janlelis/wcswidth-ruby
FFI bindings to libc's wcswidth() to determine the actual display width of strings
https://github.com/janlelis/wcswidth-ruby
ffi-bindings ruby unicode
Last synced: 10 months ago
JSON representation
FFI bindings to libc's wcswidth() to determine the actual display width of strings
- Host: GitHub
- URL: https://github.com/janlelis/wcswidth-ruby
- Owner: janlelis
- License: mit
- Created: 2016-03-01T16:50:12.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2021-11-06T14:18:32.000Z (over 4 years ago)
- Last Synced: 2025-08-01T11:58:16.401Z (11 months ago)
- Topics: ffi-bindings, ruby, unicode
- Language: Ruby
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# wcswidth [![[version]](https://badge.fury.io/rb/wcswidth.svg)](https://badge.fury.io/rb/wcswidth) [![[ci]](https://github.com/janlelis/wcswidth/workflows/Test/badge.svg)](https://github.com/janlelis/wcswidth/actions?query=workflow%3ATest)
Determine terminal display width (columns) of Ruby strings via [FFI bindings](https://github.com/ffi/ffi/wiki) to libc's [wcswidth()](http://man7.org/linux/man-pages/man3/wcswidth.3.html) function.
See [unicode/display_width](https://github.com/janlelis/unicode-display_width) for a Ruby-only unicode data based approach.
## Usage
```ruby
require 'wcswidth/kernel_method'
# full width chars
wcswidth("!") # => 2
wcswidth("一") # => 2
# single width chars
wcswidth("A") # => 1
wcswidth("·") # => 1
# zero width chars
wcswidth("ֿ") # => 0
wcswidth("\0") # => 0
# control chars
wcswidth("\x01") # => -1
wcswidth("\n") # => -1
```
Without opting in for `wcswidth/kernel_method` it is `Wcswidth.of("string")`
## MIT License
Copyright (C) 2016 Jan Lelis . Released under the MIT license.