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

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

#centreArray

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.

Returns:

  • (Array)


118
119
120
# File 'lib/vedeu/terminal/terminal.rb', line 118

def centre
  [(height / 2), (width / 2)]
end

#centre_xFixnum

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

Returns:

  • (Fixnum)


134
135
136
# File 'lib/vedeu/terminal/terminal.rb', line 134

def centre_x
  centre[-1]
end

#centre_yFixnum

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

Returns:

  • (Fixnum)


126
127
128
# File 'lib/vedeu/terminal/terminal.rb', line 126

def centre_y
  centre[0]
end

#clearString

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.

Examples:

Vedeu.clear

Returns:

  • (String)


92
93
94
# File 'lib/vedeu/terminal/terminal.rb', line 92

def clear
  output(Vedeu.esc.clear)
end

#consoleFile

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.

Returns:

  • (File)


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.

Returns:

  • (String)


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.

Parameters:

  • block (Proc)
  • mode (Symbol)


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.

Parameters:

  • block (Proc)

Returns:

  • (Array)

Raises:



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

#originFixnum 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.

Returns:

  • (Fixnum)


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.

Parameters:

  • streams (String|Array)

Returns:

  • (Array)


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

#resizeBoolean

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:



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_screenString

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.

Returns:

  • (String)


102
103
104
# File 'lib/vedeu/terminal/terminal.rb', line 102

def restore_screen
  output(Vedeu.esc.screen_exit)
end

#set_cursor_modeString

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.

Returns:

  • (String)


110
111
112
# File 'lib/vedeu/terminal/terminal.rb', line 110

def set_cursor_mode
  output(Vedeu.esc.show_cursor) unless raw_mode?
end

#sizeArray<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.

Returns:

  • (Array<Fixnum>)


152
153
154
# File 'lib/vedeu/terminal/terminal.rb', line 152

def size
  console.winsize
end