Class: TTYString::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/tty_string/renderer.rb

Overview

turns the text string into screen instructions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRenderer

Returns a new instance of Renderer.



9
10
11
# File 'lib/tty_string/renderer.rb', line 9

def initialize
  @screen = Screen.new
end

Instance Attribute Details

#screenObject (readonly)

Returns the value of attribute screen.



7
8
9
# File 'lib/tty_string/renderer.rb', line 7

def screen
  @screen
end

Instance Method Details

#csi_A(rows = 1) ⇒ Object

rubocop:disable Naming/MethodName



22
23
24
# File 'lib/tty_string/renderer.rb', line 22

def csi_A(rows = 1)
  cursor.up(rows)
end

#csi_B(rows = 1) ⇒ Object



26
27
28
# File 'lib/tty_string/renderer.rb', line 26

def csi_B(rows = 1)
  cursor.down(rows)
end

#csi_C(cols = 1) ⇒ Object



30
31
32
# File 'lib/tty_string/renderer.rb', line 30

def csi_C(cols = 1)
  cursor.right(cols)
end

#csi_D(cols = 1) ⇒ Object



34
35
36
# File 'lib/tty_string/renderer.rb', line 34

def csi_D(cols = 1)
  cursor.left(cols)
end

#csi_E(rows = 1) ⇒ Object



38
39
40
41
# File 'lib/tty_string/renderer.rb', line 38

def csi_E(rows = 1)
  cursor.down(rows)
  cursor.col = 0
end

#csi_F(rows = 1) ⇒ Object



43
44
45
46
# File 'lib/tty_string/renderer.rb', line 43

def csi_F(rows = 1)
  cursor.up(rows)
  cursor.col = 0
end

#csi_G(col = 1) ⇒ Object



48
49
50
# File 'lib/tty_string/renderer.rb', line 48

def csi_G(col = 1)
  cursor.col = col.to_i - 1 # cursor is zero indexed, arg is 1 indexed
end

#csi_H(row = 1, col = 1) ⇒ Object Also known as: csi_f



52
53
54
55
56
# File 'lib/tty_string/renderer.rb', line 52

def csi_H(row = 1, col = 1)
  # cursor is zero indexed, arg is 1 indexed
  cursor.row = row.to_i - 1
  cursor.col = col.to_i - 1
end

#csi_J(mode = 0) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/tty_string/renderer.rb', line 59

def csi_J(mode = 0)
  case mode.to_i
  when 0 then screen.clear_forward
  when 1 then screen.clear_backward
  when 2, 3 then screen.clear
  end
end

#csi_K(mode = 0) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/tty_string/renderer.rb', line 67

def csi_K(mode = 0)
  case mode.to_i
  when 0 then screen.clear_line_forward
  when 1 then screen.clear_line_backward
  when 2 then screen.clear_line
  end
end

#csi_m(*args) ⇒ Object



75
76
# File 'lib/tty_string/renderer.rb', line 75

def csi_m(*args)
end

#slash_bObject

rubocop:enable Naming/MethodName



79
80
81
82
# File 'lib/tty_string/renderer.rb', line 79

def slash_b
  cursor.left
  screen.clear_at_cursor
end

#slash_nObject



84
85
86
87
88
# File 'lib/tty_string/renderer.rb', line 84

def slash_n
  cursor.down
  cursor.col = 0
  screen.write('')
end

#slash_rObject



90
91
92
# File 'lib/tty_string/renderer.rb', line 90

def slash_r
  cursor.col = 0
end

#slash_tObject



94
95
96
# File 'lib/tty_string/renderer.rb', line 94

def slash_t
  cursor.right(8 - (cursor.col % 8))
end

#to_sObject



13
14
15
# File 'lib/tty_string/renderer.rb', line 13

def to_s
  screen.to_s
end

#write(string) ⇒ Object



17
18
19
# File 'lib/tty_string/renderer.rb', line 17

def write(string)
  screen.write(string)
end