summaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2023-05-13 19:36:48 -0300
committericebaker <icebaker@proton.me>2023-05-13 19:36:48 -0300
commitb5dbdd4ec2b7d7cc3d7572ad8bd308ed3fdd417d (patch)
treebf93ab649db65d807db2a0cb5b90b0daf98a6044 /controllers
parent9103778fe438ad4b0c90dce60bf77fc812290fc4 (diff)
fixing prefix and suffix
Diffstat (limited to 'controllers')
-rw-r--r--controllers/interfaces/repl.rb25
-rw-r--r--controllers/session.rb16
2 files changed, 15 insertions, 26 deletions
diff --git a/controllers/interfaces/repl.rb b/controllers/interfaces/repl.rb
index 9415674..ee6234b 100644
--- a/controllers/interfaces/repl.rb
+++ b/controllers/interfaces/repl.rb
@@ -4,19 +4,20 @@ require 'pry'
require 'rainbow'
require_relative '../../logic/helpers/hash'
+require_relative '../../logic/cartridge/affixes'
module NanoBot
module Controllers
module Interfaces
module REPL
def self.start(cartridge, session)
- prefix = build_prefix(cartridge)
- postfix = build_postfix(cartridge)
+ prefix = Logic::Cartridge::Affixes.get(cartridge, :repl, :output, :prefix)
+ suffix = Logic::Cartridge::Affixes.get(cartridge, :repl, :output, :suffix)
if Logic::Helpers::Hash.fetch(cartridge, %i[behaviors boot instruction])
session.print(prefix) unless prefix.nil?
session.boot(mode: 'repl')
- session.print(postfix) unless postfix.nil?
+ session.print(suffix) unless suffix.nil?
session.print("\n")
end
@@ -29,9 +30,9 @@ module NanoBot
)
Pry.commands.block_command(/(.*)/, 'handler') do |line|
- session.print(postfix) unless postfix.nil?
+ session.print(prefix) unless prefix.nil?
session.evaluate_and_print(line, mode: 'repl')
- session.print(postfix) unless postfix.nil?
+ session.print(suffix) unless suffix.nil?
session.print("\n")
session.flush
end
@@ -39,20 +40,6 @@ module NanoBot
Pry.start
end
- def self.build_prefix(cartridge)
- repl = Logic::Helpers::Hash.fetch(cartridge, %i[interfaces repl])
- return "\n" if repl.nil? || !repl.key?(:prefix) # default
-
- repl[:prefix]
- end
-
- def self.build_postfix(cartridge)
- repl = Logic::Helpers::Hash.fetch(cartridge, %i[interfaces repl])
- return "\n" if repl.nil? || !repl.key?(:postfix) # default
-
- repl[:postfix]
- end
-
def self.build_prompt(prompt)
result = ''
diff --git a/controllers/session.rb b/controllers/session.rb
index d61fdd5..3d5d707 100644
--- a/controllers/session.rb
+++ b/controllers/session.rb
@@ -82,17 +82,19 @@ module NanoBot
ready = false
@provider.evaluate(input) do |output, finished|
- output = Logic::Cartridge::Interaction.output(
- @cartridge, mode.to_sym, output, streaming, finished
- )
-
- output[:message] = Components::Adapter.apply(:output, output[:message])
-
updated_at = Time.now
if finished
- @state[:history] << output
+ @state[:history] << Marshal.load(Marshal.dump(output))
+
+ output = Logic::Cartridge::Interaction.output(
+ @cartridge, mode.to_sym, output, streaming, finished
+ )
+
+ output[:message] = Components::Adapter.apply(:output, output[:message])
+
self.print(output[:message]) unless streaming
+
ready = true
flush
elsif streaming