Class: Doublespeak::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/doublespeak/display.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @ostream = options[:ostream] || $stdout
  @istream = options[:istream] || $stdin
  @reader = TTY::Reader.new

  colorizer = Pastel::new
  @format_result = options[:format_result] || colorizer.white.dim.detach
  @format_result_textmatch = options[:format_result_textmatch] || colorizer.cyan.dim.detach
  @format_selected_result = options[:format_selected_result] || colorizer.green.dim.detach

  c, r = *cursor_position
  @origin_col = options[:origin_col] || c
  @origin_row = options[:origin_row] || r
  @screen_width = options[:screen_width] || IO.console.winsize[1]
end

Instance Attribute Details

#format_resultObject (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_textmatchObject (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_resultObject (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_colObject (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_rowObject (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_widthObject (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_lineObject



34
35
36
# File 'lib/doublespeak/display.rb', line 34

def clear_to_end_of_line
  write_escaped "[K"
end

#move_to_originObject



30
31
32
# File 'lib/doublespeak/display.rb', line 30

def move_to_origin
  write_escaped "[#{origin_row};#{origin_col}H"
end

#readObject



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

#widthObject



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