Module: Clack::Core::Cursor
- Defined in:
- lib/clack/core/cursor.rb
Overview
ANSI escape sequences for cursor control. See: en.wikipedia.org/wiki/ANSI_escape_code
Class Attribute Summary collapse
-
.enabled ⇒ Object
writeonly
Override enabled state for testing or special cases.
Class Method Summary collapse
-
.back(n = 1) ⇒ Object
CUB: Cursor Back.
-
.clear_down ⇒ Object
ED: Erase below cursor.
-
.clear_line ⇒ Object
Erasing EL: Erase entire line.
-
.clear_screen ⇒ Object
ED: Erase entire screen.
-
.clear_to_end ⇒ Object
EL: Erase to end of line.
-
.column(n) ⇒ Object
CHA: Cursor Horizontal Absolute.
-
.down(n = 1) ⇒ Object
CUD: Cursor Down.
- .enabled? ⇒ Boolean
-
.forward(n = 1) ⇒ Object
CUF: Cursor Forward.
-
.hide ⇒ Object
Visibility DECTCEM: Hide cursor.
-
.home ⇒ Object
CUP: Home position (1,1).
-
.restore ⇒ Object
DECRC: Restore Cursor Position.
-
.save ⇒ Object
Save/restore DECSC: Save Cursor Position.
-
.show ⇒ Object
DECTCEM: Show cursor.
-
.to(x, y) ⇒ Object
Absolute positioning CUP: Cursor Position.
-
.up(n = 1) ⇒ Object
Movement (CSI sequences) CUU: Cursor Up.
Class Attribute Details
.enabled=(value) ⇒ Object (writeonly)
Override enabled state for testing or special cases
11 12 13 |
# File 'lib/clack/core/cursor.rb', line 11 def enabled=(value) @enabled = value end |
Class Method Details
.back(n = 1) ⇒ Object
CUB: Cursor Back
33 |
# File 'lib/clack/core/cursor.rb', line 33 def back(n = 1) = enabled? ? "\e[#{n}D" : "" |
.clear_down ⇒ Object
ED: Erase below cursor
55 56 |
# File 'lib/clack/core/cursor.rb', line 55 def clear_down = enabled? ? "\e[J" : "" # ED: Erase entire screen |
.clear_line ⇒ Object
Erasing EL: Erase entire line
51 52 |
# File 'lib/clack/core/cursor.rb', line 51 def clear_line = enabled? ? "\e[2K" : "" # EL: Erase to end of line |
.clear_screen ⇒ Object
ED: Erase entire screen
57 |
# File 'lib/clack/core/cursor.rb', line 57 def clear_screen = enabled? ? "\e[2J" : "" |
.clear_to_end ⇒ Object
EL: Erase to end of line
53 54 |
# File 'lib/clack/core/cursor.rb', line 53 def clear_to_end = enabled? ? "\e[K" : "" # ED: Erase below cursor |
.column(n) ⇒ Object
CHA: Cursor Horizontal Absolute
39 40 |
# File 'lib/clack/core/cursor.rb', line 39 def column(n) = enabled? ? "\e[#{n}G" : "" # CUP: Home position (1,1) |
.down(n = 1) ⇒ Object
CUD: Cursor Down
29 30 |
# File 'lib/clack/core/cursor.rb', line 29 def down(n = 1) = enabled? ? "\e[#{n}B" : "" # CUF: Cursor Forward |
.enabled? ⇒ Boolean
13 14 15 16 17 |
# File 'lib/clack/core/cursor.rb', line 13 def enabled? return @enabled unless @enabled.nil? Environment.colors_supported? end |
.forward(n = 1) ⇒ Object
CUF: Cursor Forward
31 32 |
# File 'lib/clack/core/cursor.rb', line 31 def forward(n = 1) = enabled? ? "\e[#{n}C" : "" # CUB: Cursor Back |
.hide ⇒ Object
Visibility DECTCEM: Hide cursor
21 22 |
# File 'lib/clack/core/cursor.rb', line 21 def hide = enabled? ? "\e[?25l" : "" # DECTCEM: Show cursor |
.home ⇒ Object
CUP: Home position (1,1)
41 |
# File 'lib/clack/core/cursor.rb', line 41 def home = enabled? ? "\e[H" : "" |
.restore ⇒ Object
DECRC: Restore Cursor Position
47 |
# File 'lib/clack/core/cursor.rb', line 47 def restore = enabled? ? "\e8" : "" |
.save ⇒ Object
Save/restore DECSC: Save Cursor Position
45 46 |
# File 'lib/clack/core/cursor.rb', line 45 def save = enabled? ? "\e7" : "" # DECRC: Restore Cursor Position |
.show ⇒ Object
DECTCEM: Show cursor
23 |
# File 'lib/clack/core/cursor.rb', line 23 def show = enabled? ? "\e[?25h" : "" |
.to(x, y) ⇒ Object
Absolute positioning CUP: Cursor Position
37 38 |
# File 'lib/clack/core/cursor.rb', line 37 def to(x, y) = enabled? ? "\e[#{y};#{x}H" : "" # CHA: Cursor Horizontal Absolute |
.up(n = 1) ⇒ Object
Movement (CSI sequences) CUU: Cursor Up
27 28 |
# File 'lib/clack/core/cursor.rb', line 27 def up(n = 1) = enabled? ? "\e[#{n}A" : "" # CUD: Cursor Down |