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.
-
#theme ⇒ Object
Returns the value of attribute theme.
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
#initialize ⇒ Platform
Set up Platform.
26 27 28 29 30 31 32 33 |
# File 'lib/gloo/app/platform.rb', line 26 def initialize @prompt = Gloo::App::Prompt.new( self ) @table = Gloo::App::Table.new( self ) # Default theme, in case this platform is ever used # standalone, without an Engine to set the real one. @theme = Gloo::App::Theme.new end |
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 |
#theme ⇒ Object
Returns the value of attribute theme.
21 22 23 |
# File 'lib/gloo/app/platform.rb', line 21 def theme @theme end |
Instance Method Details
#clear_screen ⇒ Object
Clear the screen.
61 62 63 |
# File 'lib/gloo/app/platform.rb', line 61 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).
106 107 108 109 110 111 |
# File 'lib/gloo/app/platform.rb', line 106 def cols _rows, columns = $stdout.winsize return columns rescue StandardError return DEFAULT_COLS end |
#get_colorized_string(str, color) ⇒ Object
Get colorized string.
80 81 82 83 |
# File 'lib/gloo/app/platform.rb', line 80 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.
68 69 70 |
# File 'lib/gloo/app/platform.rb', line 68 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).
94 95 96 97 98 99 |
# File 'lib/gloo/app/platform.rb', line 94 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.
48 49 50 51 52 53 54 55 56 |
# File 'lib/gloo/app/platform.rb', line 48 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.
38 39 40 |
# File 'lib/gloo/app/platform.rb', line 38 def show( msg ) puts msg end |