Class: Tempest::REPL::AsyncOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/tempest/repl/async_output.rb

Overview

Wraps an IO so writes from background threads (Jetstream events) don’t smash Reline’s prompt. Each puts clears the current terminal line and then asks Reline to re-render the prompt and the user’s in-flight input buffer. Best-effort: if Reline isn’t loaded or the rerender hook isn’t available, we just degrade to a normal write.

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ AsyncOutput

Returns a new instance of AsyncOutput.



11
12
13
# File 'lib/tempest/repl/async_output.rb', line 11

def initialize(io)
  @io = io
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



48
49
50
# File 'lib/tempest/repl/async_output.rb', line 48

def method_missing(name, *args, **kwargs, &block)
  @io.send(name, *args, **kwargs, &block)
end

Instance Method Details

#flushObject



36
37
38
# File 'lib/tempest/repl/async_output.rb', line 36

def flush
  @io.flush if @io.respond_to?(:flush)
end


28
29
30
# File 'lib/tempest/repl/async_output.rb', line 28

def print(*args)
  @io.print(*args)
end

#puts(*lines) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tempest/repl/async_output.rb', line 15

def puts(*lines)
  if lines.empty?
    @io.print "\r\e[2K"
    @io.puts
  else
    lines.each do |line|
      @io.print "\r\e[2K"
      @io.puts line
    end
  end
  rerender_prompt
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/tempest/repl/async_output.rb', line 44

def respond_to_missing?(name, include_private = false)
  @io.respond_to?(name, include_private)
end

#tty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/tempest/repl/async_output.rb', line 40

def tty?
  @io.respond_to?(:tty?) ? @io.tty? : false
end

#write(*args) ⇒ Object



32
33
34
# File 'lib/tempest/repl/async_output.rb', line 32

def write(*args)
  @io.write(*args)
end