Sha256: 455177d8baea7c10f488b2bfe83d9bf3edcb16ea75bc061df61d8740e6472d1d

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# wcswidth [![[version]](https://badge.fury.io/rb/wcswidth.svg)](http://badge.fury.io/rb/wcswidth)  [![[travis]](https://travis-ci.org/janlelis/wcswidth-ruby.png)](https://travis-ci.org/janlelis/wcswidth-ruby)

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 <http://janlelis.com>. Released under the MIT license.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wcswidth-1.0.0 README.md