Class: Tempest::REPL::Screen
- Inherits:
-
Object
- Object
- Tempest::REPL::Screen
show all
- Defined in:
- lib/tempest/repl/screen.rb
Overview
Implements the earthquake-style split layout: the bottom row holds the tempest> prompt, while the rest of the terminal scrolls timeline lines in from below. Built on the DECSTBM (top/bottom margin) escape sequence so we don’t need a full curses screen.
Sequences used:
CSI top;bottom r set scrolling region
CSI r reset scrolling region (full screen)
CSI row;col H move cursor
ESC 7 / ESC 8 save/restore cursor (DECSC/DECRC)
Instance Method Summary
collapse
Constructor Details
#initialize(io:, rows: nil) ⇒ Screen
Returns a new instance of Screen.
16
17
18
19
20
21
|
# File 'lib/tempest/repl/screen.rb', line 16
def initialize(io:, rows: nil)
@io = io
@rows = rows
@enabled = false
@mutex = Mutex.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
85
86
87
|
# File 'lib/tempest/repl/screen.rb', line 85
def method_missing(name, *args, **kwargs, &block)
@io.send(name, *args, **kwargs, &block)
end
|
Instance Method Details
#disable ⇒ Object
35
36
37
38
39
40
|
# File 'lib/tempest/repl/screen.rb', line 35
def disable
return unless @enabled
@io.print "\e[r"
@io.flush if @io.respond_to?(:flush)
@enabled = false
end
|
#enable ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/tempest/repl/screen.rb', line 23
def enable
return unless @io.respond_to?(:tty?) && @io.tty?
rows = @rows || detect_rows
return unless rows && rows >= 4
@rows = rows
@io.print "\e[1;#{rows - 1}r" @io.print "\e[#{rows};1H" @io.flush if @io.respond_to?(:flush)
@enabled = true
end
|
#enabled? ⇒ Boolean
42
43
44
|
# File 'lib/tempest/repl/screen.rb', line 42
def enabled?
@enabled
end
|
#flush ⇒ Object
73
74
75
|
# File 'lib/tempest/repl/screen.rb', line 73
def flush
@io.flush if @io.respond_to?(:flush)
end
|
#print(*args) ⇒ Object
65
66
67
|
# File 'lib/tempest/repl/screen.rb', line 65
def print(*args)
@io.print(*args)
end
|
#puts(*lines) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/tempest/repl/screen.rb', line 46
def puts(*lines)
@mutex.synchronize do
if @enabled
flat = lines.empty? ? [""] : lines.flat_map { |l| l.to_s.split("\n") }
flat.each { |line| insert_above_prompt(line) }
else
(lines.empty? ? [""] : lines).each do |line|
@io.print "\r\e[2K"
@io.puts line
end
@io.flush if @io.respond_to?(:flush)
end
end
rerender_prompt
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
81
82
83
|
# File 'lib/tempest/repl/screen.rb', line 81
def respond_to_missing?(name, include_private = false)
@io.respond_to?(name, include_private)
end
|
#tty? ⇒ Boolean
77
78
79
|
# File 'lib/tempest/repl/screen.rb', line 77
def tty?
@io.respond_to?(:tty?) ? @io.tty? : false
end
|
#write(*args) ⇒ Object
69
70
71
|
# File 'lib/tempest/repl/screen.rb', line 69
def write(*args)
@io.write(*args)
end
|