Class: Doublespeak::Display
- Inherits:
-
Object
- Object
- Doublespeak::Display
- Defined in:
- lib/doublespeak/display.rb
Instance Attribute Summary collapse
-
#format_result ⇒ Object
readonly
Returns the value of attribute format_result.
-
#format_result_textmatch ⇒ Object
readonly
Returns the value of attribute format_result_textmatch.
-
#format_selected_result ⇒ Object
readonly
Returns the value of attribute format_selected_result.
-
#origin_col ⇒ Object
readonly
Returns the value of attribute origin_col.
-
#origin_row ⇒ Object
readonly
Returns the value of attribute origin_row.
-
#screen_width ⇒ Object
readonly
Returns the value of attribute screen_width.
Instance Method Summary collapse
- #clear_to_end_of_line ⇒ Object
-
#initialize(options) ⇒ Display
constructor
A new instance of Display.
- #move_to_origin ⇒ Object
- #read ⇒ Object
- #set_cursor_visible(visible = true) ⇒ Object
- #width ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(options) ⇒ Display
Returns a new instance of Display.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/doublespeak/display.rb', line 10 def initialize() @ostream = [:ostream] || $stdout @istream = [:istream] || $stdin @reader = TTY::Reader.new colorizer = Pastel::new @format_result = [:format_result] || colorizer.white.dim.detach @format_result_textmatch = [:format_result_textmatch] || colorizer.cyan.dim.detach @format_selected_result = [:format_selected_result] || colorizer.green.dim.detach c, r = *cursor_position @origin_col = [:origin_col] || c @origin_row = [:origin_row] || r @screen_width = [:screen_width] || IO.console.winsize[1] end |
Instance Attribute Details
#format_result ⇒ Object (readonly)
Returns the value of attribute format_result.
7 8 9 |
# File 'lib/doublespeak/display.rb', line 7 def format_result @format_result end |
#format_result_textmatch ⇒ Object (readonly)
Returns the value of attribute format_result_textmatch.
7 8 9 |
# File 'lib/doublespeak/display.rb', line 7 def format_result_textmatch @format_result_textmatch end |
#format_selected_result ⇒ Object (readonly)
Returns the value of attribute format_selected_result.
7 8 9 |
# File 'lib/doublespeak/display.rb', line 7 def format_selected_result @format_selected_result end |
#origin_col ⇒ Object (readonly)
Returns the value of attribute origin_col.
7 8 9 |
# File 'lib/doublespeak/display.rb', line 7 def origin_col @origin_col end |
#origin_row ⇒ Object (readonly)
Returns the value of attribute origin_row.
7 8 9 |
# File 'lib/doublespeak/display.rb', line 7 def origin_row @origin_row end |
#screen_width ⇒ Object (readonly)
Returns the value of attribute screen_width.
7 8 9 |
# File 'lib/doublespeak/display.rb', line 7 def screen_width @screen_width end |
Instance Method Details
#clear_to_end_of_line ⇒ Object
34 35 36 |
# File 'lib/doublespeak/display.rb', line 34 def clear_to_end_of_line write_escaped "[K" end |
#move_to_origin ⇒ Object
30 31 32 |
# File 'lib/doublespeak/display.rb', line 30 def move_to_origin write_escaped "[#{origin_row};#{origin_col}H" end |
#read ⇒ Object
46 47 48 |
# File 'lib/doublespeak/display.rb', line 46 def read reader.read_char end |
#set_cursor_visible(visible = true) ⇒ Object
38 39 40 |
# File 'lib/doublespeak/display.rb', line 38 def set_cursor_visible(visible=true) write_escaped(visible ? "[?25h" : "[?25l") end |
#width ⇒ Object
26 27 28 |
# File 'lib/doublespeak/display.rb', line 26 def width screen_width - origin_col end |
#write(str) ⇒ Object
42 43 44 |
# File 'lib/doublespeak/display.rb', line 42 def write(str) ostream << str end |