Class: Bash_Visual::Console

Inherits:
Object
  • Object
show all
Includes:
Painter
Defined in:
lib/bash-visual/console.rb

Constant Summary collapse

OUTPUT_STRING =
0
OUTPUT_WITHOUT_BLOCK =
1
OUTPUT_WITH_BLOCK =
2
@@mutex =
Mutex.new

Constants included from Painter

Painter::BORDER_UTF, Painter::BORDER_UTF_DOUBLE, Painter::BORDER_UTF_ROUND

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Painter

#draw_border, #draw_filled_rectangle, #draw_window

Constructor Details

#initialize(font = Font.new, way_output = OUTPUT_WITHOUT_BLOCK, builder = Builder.new) ⇒ Console

Returns a new instance of Console.

Parameters:



15
16
17
18
19
20
21
# File 'lib/bash-visual/console.rb', line 15

def initialize (font = Font.new, way_output = OUTPUT_WITHOUT_BLOCK, builder = Builder.new)
  @current_x = 0
  @current_y = 0
  @font = font
  @way_output = way_output
  @builder = builder
end

Instance Attribute Details

#current_xObject (readonly)

Returns the value of attribute current_x.



10
11
12
# File 'lib/bash-visual/console.rb', line 10

def current_x
  @current_x
end

#current_yObject (readonly)

Returns the value of attribute current_y.



10
11
12
# File 'lib/bash-visual/console.rb', line 10

def current_y
  @current_y
end

#fontObject

Returns the value of attribute font.



10
11
12
# File 'lib/bash-visual/console.rb', line 10

def font
  @font
end

Class Method Details

.colsObject



82
83
84
# File 'lib/bash-visual/console.rb', line 82

def cols
  `tput cols`
end

.linesObject



78
79
80
# File 'lib/bash-visual/console.rb', line 78

def lines
  `tput lines`
end

Instance Method Details

#clearObject

Clear the screen and move to (0,0)



54
55
56
57
58
# File 'lib/bash-visual/console.rb', line 54

def clear
  @current_x = 0
  @current_y = 0
  print @builder.clear
end

#erase_to_end_lineObject



49
50
51
# File 'lib/bash-visual/console.rb', line 49

def erase_to_end_line
  print @builder.erase_to_end_line
end

#move_position(offset_x, offset_y) ⇒ Object



28
29
30
31
32
# File 'lib/bash-visual/console.rb', line 28

def move_position(offset_x, offset_y)
  @current_x += offset_x
  @current_y += offset_y
  print @builder.move_position(offset_x, offset_y)
end

#position=(coord) ⇒ Object



23
24
25
26
# File 'lib/bash-visual/console.rb', line 23

def position= coord
  @current_x , @current_y = *coord
  print @builder.set_position(@current_x, @current_y)
end

#write(text, font = @font) ⇒ Object



41
42
43
# File 'lib/bash-visual/console.rb', line 41

def write (text, font = @font)
  print @builder.write(text, font)
end

#write_ln(text = '', font = @font) ⇒ Object



45
46
47
# File 'lib/bash-visual/console.rb', line 45

def write_ln (text = '', font = @font)
  print @builder.write_ln(text, font)
end

#write_to_position(x, y, text, font = @font) ⇒ Object

Записать что-то в определенной позиции, а потом вернуться на текущую Если необходимо сохранить позицию после записи - используйте связку move_position/position= и write



37
38
39
# File 'lib/bash-visual/console.rb', line 37

def write_to_position (x, y, text, font = @font)
  print @builder.write_to_position(x, y, text, font)
end