Sha256: 4b774dbd1d238c13705bcb9d3b6a52793537326e8a41cc7f963c91210c699fb5

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

# ruby-winsize

ruby-winsize is a small library that lets you get and set the winsize of a terminal.

ruby-winsize adds two methods (`winsize` and `winsize=`) to for use with any
`IO` instance for a TTY device. The `Winsize::Winsize` class is an intermediate
form that is used for `ioctl` calls to the TTY device.

## Installing

### Recommended

```
gem install winsize
```

### Edge

```
git clone https://github.com/samuelkadolph/ruby-winsize
cd ruby-winsize && rake install
```

## Usage

To get the size of the `$stdout` terminal.

```ruby
require "winsize"

size = $stdout.winsize
puts "Your terminal is #{size.columns}x#{size.rows}"
puts "Your terminal is #{size.horizontal_pixels}px*#{size.vertical_pixels}px"
```

To set the size of a pty terminal.
This is useful if you are running a subshell and want the subshell to have the
same output size as the terminal you yourself are running in.

You might think it would be useful to set the winsize of `$stdout` it actually
isn't since the terminal is usually limited by the monitor size or the terminal
application and increasing the size messes with trimming logic.

```ruby
require "pty"
require "winsize"

size = Winsize.new(32, 160)
# or
# size = $stdout.winsize

input, output, pid = PTY.spawn

output.winsize = size
# or
# output.winsize = 32, 160
```

You may want to combine `winsize` and catching the [`SIGWINCH`](http://en.wikipedia.org/wiki/SIGWINCH) signal so you
update something that your terminal has been resized.

```ruby
require "winsize"

puts "Terminal size is #{$stdout.winsize.columns}x#{$stdout.winsize.rows}"

Signal.trap "WINCH" do
  puts "Terminal resized to #{$stdout.winsize.columns}x#{$stdout.winsize.rows}"
end

loop { sleep(10) }
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
winsize-1.0.1 README.md