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
Instance Attribute Summary collapse
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Instance Method Summary collapse
-
#clear_screen ⇒ Object
Clear the screen.
-
#cols ⇒ Object
Get the number of horizontal columns on screen.
-
#edit(initial_value) ⇒ Object
Edit some temporary text and return the edited text.
-
#getColorizedString(str, color) ⇒ Object
Get colorized string.
-
#getFileMech(engine) ⇒ Object
Get the file mechanism for this platform.
-
#initialize ⇒ Platform
constructor
Set up Platform.
-
#lines ⇒ Object
——————————————————————— Sceen helpers ———————————————————————.
-
#prompt_cmd ⇒ Object
Prompt for the next command.
-
#show(msg, md = false, page = false) ⇒ Object
Show a message.
-
#show_table(headers, data, title = nil) ⇒ Object
Show the given table data.
Constructor Details
#initialize ⇒ Platform
Set up Platform.
29 30 31 |
# File 'lib/gloo/app/platform.rb', line 29 def initialize @prompt = TTY::Prompt.new end |
Instance Attribute Details
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
24 25 26 |
# File 'lib/gloo/app/platform.rb', line 24 def prompt @prompt end |
Instance Method Details
#clear_screen ⇒ Object
Clear the screen.
60 61 62 63 64 |
# File 'lib/gloo/app/platform.rb', line 60 def clear_screen @cursor ||= TTY::Cursor print @cursor.clear_screen print @cursor.move_to( 0, 0 ) end |
#cols ⇒ Object
Get the number of horizontal columns on screen.
139 140 141 |
# File 'lib/gloo/app/platform.rb', line 139 def cols TTY::Screen.cols end |
#edit(initial_value) ⇒ Object
Edit some temporary text and return the edited text.
69 70 71 72 73 74 |
# File 'lib/gloo/app/platform.rb', line 69 def edit initial_value tmp = File.join( $settings.tmp_path, DEFAULT_TMP_FILE ) File.open( tmp, 'w' ) { |file| file.write( initial_value ) } TTY::Editor.open( tmp ) return File.read( tmp ) end |
#getColorizedString(str, color) ⇒ Object
Get colorized string.
90 91 92 93 |
# File 'lib/gloo/app/platform.rb', line 90 def getColorizedString( str, color ) colorized = ColorizedString[ str.to_s ].colorize( color ) return colorized.to_s end |
#getFileMech(engine) ⇒ Object
Get the file mechanism for this platform.
79 80 81 |
# File 'lib/gloo/app/platform.rb', line 79 def getFileMech( engine ) return Gloo::Persist::DiscMech.new( engine ) end |
#lines ⇒ Object
Sceen helpers
Get the number of vertical lines on screen.
132 133 134 |
# File 'lib/gloo/app/platform.rb', line 132 def lines TTY::Screen.rows end |
#prompt_cmd ⇒ Object
Prompt for the next command.
53 54 55 |
# File 'lib/gloo/app/platform.rb', line 53 def prompt_cmd return @prompt.ask( default_prompt ) end |
#show(msg, md = false, page = false) ⇒ Object
Show a message.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gloo/app/platform.rb', line 36 def show( msg, md=false, page=false ) if md msg = TTY::Markdown.parse msg end if page # pager = TTY::Pager::SystemPager.new command: 'less -R' pager = TTY::Pager.new pager.page( msg ) else puts msg end end |
#show_table(headers, data, title = nil) ⇒ Object
Show the given table data.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/gloo/app/platform.rb', line 102 def show_table( headers, data, title = nil ) pastel = ::Pastel.new if headers table = TTY::Table.new headers, data else table = TTY::Table.new rows: data end pad = [ 0, 1, 0, 1 ] rendered = table.render( :ascii, indent: 2, padding: pad ) do |r| r.border.style = :blue r.filter = proc do |val, row_index, _col_index| # col_index % 2 == 1 ? pastel.red.on_green(val) : val if headers && row_index.zero? pastel.blue( val ) else row_index.odd? ? pastel.white( val ) : pastel.yellow( val ) end end end puts puts "#{title.white}" if title puts "#{rendered}\n\n" end |