Class: Libuv::TTY

Inherits:
Handle show all
Includes:
Stream
Defined in:
lib/libuv/tty.rb

Constant Summary

Constants included from Stream

Stream::BACKLOG_ERROR, Stream::CLOSED_HANDLE_ERROR, Stream::STREAM_CLOSED_ERROR, Stream::WRITE_ERROR

Constants included from Assertions

Assertions::MSG_NO_PROC

Constants inherited from Q::Promise

Q::Promise::MAKE_PROMISE

Instance Attribute Summary

Attributes inherited from Handle

#closed, #reactor, #storage

Attributes inherited from Q::Promise

#trace

Instance Method Summary collapse

Methods included from Stream

#close_write, #flush, included, #listen, #progress, #read, #readable?, #shutdown, #start_read, #stop_read, #try_write, #writable?, #write

Methods inherited from Handle

#active?, #close, #closed?, #closing?, #ref, #unref

Methods included from Assertions

#assert_block, #assert_boolean, #assert_type

Methods included from Resource

#check_result, #check_result!, #resolve, #to_ptr

Methods inherited from Q::DeferredPromise

#resolved?, #then

Methods inherited from Q::Promise

#catch, #finally, #progress, #ruby_catch, #value

Constructor Details

#initialize(reactor, fileno, readable) ⇒ TTY

Returns a new instance of TTY.



8
9
10
11
12
13
14
15
# File 'lib/libuv/tty.rb', line 8

def initialize(reactor, fileno, readable)
    @reactor = reactor

    tty_ptr = ::Libuv::Ext.allocate_handle_tty
    error = check_result(::Libuv::Ext.tty_init(reactor.handle, tty_ptr, fileno, readable ? 1 : 0))
    
    super(tty_ptr, error)
end

Instance Method Details

#disable_raw_modeObject



23
24
25
26
27
# File 'lib/libuv/tty.rb', line 23

def disable_raw_mode
    return if @closed
    check_result ::Libuv::Ext.tty_set_mode(handle, 0)
    self
end

#enable_raw_modeObject



17
18
19
20
21
# File 'lib/libuv/tty.rb', line 17

def enable_raw_mode
    return if @closed
    check_result ::Libuv::Ext.tty_set_mode(handle, 1)
    self
end

#reset_modeObject



29
30
31
32
# File 'lib/libuv/tty.rb', line 29

def reset_mode
    ::Libuv::Ext.tty_reset_mode
    self
end

#winsizeObject



34
35
36
37
38
39
40
# File 'lib/libuv/tty.rb', line 34

def winsize
    return [] if @closed
    width = FFI::MemoryPointer.new(:int)
    height = FFI::MemoryPointer.new(:int)
    ::Libuv::Ext.tty_get_winsize(handle, width, height)
    [width.get_int(0), height.get_int(0)]
end