summaryrefslogtreecommitdiff
path: root/controllers/session.rb
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2023-05-13 10:45:32 -0300
committericebaker <icebaker@proton.me>2023-05-13 10:45:32 -0300
commitd83ec5192442a9bd8d914c5a4856917b9653583c (patch)
treeca97e1618dd937594dc1da0a13584a46b87613eb /controllers/session.rb
parent805e5073117bc717f46da0fa7f8ab628b4fa2a7d (diff)
improving streams
Diffstat (limited to 'controllers/session.rb')
-rw-r--r--controllers/session.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/controllers/session.rb b/controllers/session.rb
index ff3b8ad..ad640c8 100644
--- a/controllers/session.rb
+++ b/controllers/session.rb
@@ -12,12 +12,13 @@ module NanoBot
STREAM_TIMEOUT_IN_SECONDS = 5
class Session
- def initialize(provider:, cartridge:, state: nil)
+ attr_accessor :stream
+
+ def initialize(provider:, cartridge:, state: nil, stream: $stdout)
+ @stream = stream
@provider = provider
@cartridge = cartridge
- @output = $stdout
-
@stateless = state.nil? || state.strip == '-' || state.strip.empty?
if @stateless
@@ -67,7 +68,7 @@ module NanoBot
process(input, mode:)
end
- def stream(interface)
+ def streaming(interface)
provider = @provider.settings.key?(:stream) ? @provider.settings[:stream] : true
interface = interface.key?(:stream) ? interface[:stream] : true
@@ -77,7 +78,7 @@ module NanoBot
def process(input, mode:)
interface = Logic::Helpers::Hash.fetch(@cartridge, [:interfaces, mode.to_sym]) || {}
- streaming = stream(interface)
+ streaming = streaming(interface)
input[:interface] = interface
@@ -105,11 +106,11 @@ module NanoBot
end
def flush
- @output.flush
+ @stream.flush
end
def print(content)
- @output.write(content)
+ @stream.write(content)
end
end
end