Module: Vedeu::Terminal Private
- Extended by:
- Forwardable, Terminal
- Includes:
- Mode
- Included in:
- Terminal
- Defined in:
- lib/vedeu/terminal/all.rb,
lib/vedeu/terminal/mode.rb,
lib/vedeu/terminal/terminal.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
This module is the direct interface between Vedeu and your terminal/ console, via Ruby’s IO core library.
Defined Under Namespace
Modules: Mode
Instance Method Summary collapse
-
#centre ⇒ Array
private
Returns a coordinate tuple of the format [y, x], where ‘y` is the row/line and `x` is the column/character.
-
#centre_x ⇒ Fixnum
private
Returns the ‘x` (column/character) component of the coodinate tuple provided by centre.
-
#centre_y ⇒ Fixnum
private
Returns the ‘y` (row/line) component of the coordinate tuple provided by centre.
-
#clear ⇒ String
private
Clears the entire terminal space.
-
#console ⇒ File
private
Provides our gateway into the wonderful rainbow-filled world of IO.
-
#debugging! ⇒ String
private
Disables the mouse and shows the cursor.
- #initialize_screen(mode, &block) ⇒ void private
-
#open(&block) ⇒ Array
private
Opens a terminal screen in either ‘raw` or `cooked` mode.
-
#origin ⇒ Fixnum
(also: #tx, #ty)
private
Returns 1.
-
#output(*streams) ⇒ Array
(also: #write)
private
Prints the streams to the screen and returns the streams.
-
#resize ⇒ Boolean
private
-
#restore_screen ⇒ String
private
Attempts to tidy up the screen just before the application terminates.
-
#set_cursor_mode ⇒ String
private
Sets the cursor to be visible unless in raw mode, whereby it will be left hidden.
-
#size ⇒ Array<Fixnum>
private
Returns a tuple containing the height and width of the current terminal.
Methods included from Mode
#cooked_mode!, #cooked_mode?, #fake_mode!, #fake_mode?, #mode, #raw_mode!, #raw_mode?, #switch_mode!, #valid_mode?, #valid_modes
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Instance Method Details
#centre ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a coordinate tuple of the format [y, x], where ‘y` is the row/line and `x` is the column/character.
118 119 120 |
# File 'lib/vedeu/terminal/terminal.rb', line 118 def centre [(height / 2), (width / 2)] end |
#centre_x ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the ‘x` (column/character) component of the coodinate tuple provided by centre
134 135 136 |
# File 'lib/vedeu/terminal/terminal.rb', line 134 def centre_x centre[-1] end |
#centre_y ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the ‘y` (row/line) component of the coordinate tuple provided by centre
126 127 128 |
# File 'lib/vedeu/terminal/terminal.rb', line 126 def centre_y centre[0] end |
#clear ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Clears the entire terminal space.
92 93 94 |
# File 'lib/vedeu/terminal/terminal.rb', line 92 def clear output(Vedeu.esc.clear) end |
#console ⇒ File
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Provides our gateway into the wonderful rainbow-filled world of IO.
160 161 162 |
# File 'lib/vedeu/terminal/terminal.rb', line 160 def console IO.console end |
#debugging! ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Disables the mouse and shows the cursor.
82 83 84 |
# File 'lib/vedeu/terminal/terminal.rb', line 82 def debugging! output(Vedeu.esc.mouse_x10_off + Vedeu.esc.show_cursor) end |
#initialize_screen(mode, &block) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
71 72 73 74 75 76 77 |
# File 'lib/vedeu/terminal/terminal.rb', line 71 def initialize_screen(mode, &block) Vedeu.log(message: "Terminal entering '#{mode}' mode") output(Vedeu.esc.screen_init) yield if block_given? end |
#open(&block) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Opens a terminal screen in either ‘raw` or `cooked` mode. On exit, attempts to restore the screen. See #restore_screen.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vedeu/terminal/terminal.rb', line 30 def open(&block) raise Vedeu::Error::RequiresBlock unless block_given? if raw_mode? || fake_mode? console.raw { initialize_screen(mode) { yield } } else console.cooked { initialize_screen(mode) { yield } } end ensure restore_screen end |
#origin ⇒ Fixnum Also known as: tx, ty
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns 1. This 1 is either the top-most or left-most coordinate of the terminal.
142 143 144 |
# File 'lib/vedeu/terminal/terminal.rb', line 142 def origin 1 end |
#output(*streams) ⇒ Array Also known as: write
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints the streams to the screen and returns the streams.
48 49 50 51 52 53 54 55 |
# File 'lib/vedeu/terminal/terminal.rb', line 48 def output(*streams) streams.each do |stream| Vedeu.log(type: :output, message: "Writing to terminal #{stream.size} bytes") console.print(stream) end end |
#resize ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 |
# File 'lib/vedeu/terminal/terminal.rb', line 60 def resize Vedeu.trigger(:_clear_) Vedeu.trigger(:_refresh_) true end |
#restore_screen ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Attempts to tidy up the screen just before the application terminates. The cursor is shown, colours are reset to terminal defaults, the terminal is told to reset, and finally we clear the last line ready for the prompt.
102 103 104 |
# File 'lib/vedeu/terminal/terminal.rb', line 102 def restore_screen output(Vedeu.esc.screen_exit) end |
#set_cursor_mode ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the cursor to be visible unless in raw mode, whereby it will be left hidden.
110 111 112 |
# File 'lib/vedeu/terminal/terminal.rb', line 110 def set_cursor_mode output(Vedeu.esc.show_cursor) unless raw_mode? end |
#size ⇒ Array<Fixnum>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a tuple containing the height and width of the current terminal.
152 153 154 |
# File 'lib/vedeu/terminal/terminal.rb', line 152 def size console.winsize end |