Class: Gloo::App::Platform
- Inherits:
-
Object
- Object
- Gloo::App::Platform
- Defined in:
- lib/gloo/app/platform.rb
Constant Summary collapse
- DEFAULT_TMP_FILE =
'tmp.txt'.freeze
- RETURN =
"\n".freeze
- DEFAULT_LINES =
24- DEFAULT_COLS =
80- PAGER_CMD =
'less -R -F -X'.freeze
Instance Attribute Summary collapse
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#clear_screen ⇒ Object
Clear the screen.
-
#cols ⇒ Object
Get the number of horizontal columns on screen.
-
#get_colorized_string(str, color) ⇒ Object
Get colorized string.
-
#get_file_mech(engine) ⇒ Object
Get the file mechanism for this platform.
-
#initialize ⇒ Platform
constructor
Set up Platform.
-
#lines ⇒ Object
--------------------------------------------------------------------- Sceen helpers ---------------------------------------------------------------------.
-
#page(msg) ⇒ Object
Show a message in a pager (less), for long content.
-
#show(msg) ⇒ Object
Show a message.
Constructor Details
Instance Attribute Details
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
20 21 22 |
# File 'lib/gloo/app/platform.rb', line 20 def prompt @prompt end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
20 21 22 |
# File 'lib/gloo/app/platform.rb', line 20 def table @table end |
Instance Method Details
#clear_screen ⇒ Object
Clear the screen.
56 57 58 |
# File 'lib/gloo/app/platform.rb', line 56 def clear_screen puts "\e[H\e[2J" end |
#cols ⇒ Object
Get the number of horizontal columns on screen. Falls back to a default when stdout has no real screen behind it (piped/captured output, no controlling TTY, etc).
101 102 103 104 105 106 |
# File 'lib/gloo/app/platform.rb', line 101 def cols _rows, columns = $stdout.winsize return columns rescue StandardError return DEFAULT_COLS end |
#get_colorized_string(str, color) ⇒ Object
Get colorized string.
75 76 77 78 |
# File 'lib/gloo/app/platform.rb', line 75 def get_colorized_string( str, color ) colorized = ColorizedString[ str.to_s ].colorize( color ) return colorized.to_s end |
#get_file_mech(engine) ⇒ Object
Get the file mechanism for this platform.
63 64 65 |
# File 'lib/gloo/app/platform.rb', line 63 def get_file_mech( engine ) return Gloo::Persist::DiscMech.new( engine ) end |
#lines ⇒ Object
Sceen helpers
Get the number of vertical lines on screen. Falls back to a default when stdout has no real screen behind it (piped/captured output, no controlling TTY, etc).
89 90 91 92 93 94 |
# File 'lib/gloo/app/platform.rb', line 89 def lines rows, _columns = $stdout.winsize return rows rescue StandardError return DEFAULT_LINES end |
#page(msg) ⇒ Object
Show a message in a pager (less), for long content. Falls back to a plain puts when there is no real terminal to page in (piped output, captured test output, etc) or when less isn't available on the system.
43 44 45 46 47 48 49 50 51 |
# File 'lib/gloo/app/platform.rb', line 43 def page( msg ) return show( msg ) unless $stdout.tty? IO.popen( PAGER_CMD, 'w' ) { |less| less.puts msg } rescue Errno::ENOENT show( msg ) rescue Errno::EPIPE # The user quit the pager early. Nothing more to do. end |
#show(msg) ⇒ Object
Show a message.
33 34 35 |
# File 'lib/gloo/app/platform.rb', line 33 def show( msg ) puts msg end |