summaryrefslogtreecommitdiff
path: root/controllers/interfaces/repl.rb
diff options
context:
space:
mode:
Diffstat (limited to 'controllers/interfaces/repl.rb')
-rw-r--r--controllers/interfaces/repl.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/controllers/interfaces/repl.rb b/controllers/interfaces/repl.rb
index ee6234b..fd16ea6 100644
--- a/controllers/interfaces/repl.rb
+++ b/controllers/interfaces/repl.rb
@@ -10,18 +10,26 @@ module NanoBot
module Controllers
module Interfaces
module REPL
+ def self.boot(cartridge, session, prefix = nil, suffix = nil, as: 'repl')
+ return unless Logic::Helpers::Hash.fetch(cartridge, %i[behaviors boot instruction])
+
+ prefix ||= Logic::Cartridge::Affixes.get(cartridge, as.to_sym, :output, :prefix)
+ suffix ||= Logic::Cartridge::Affixes.get(cartridge, as.to_sym, :output, :suffix)
+
+ session.print(prefix) unless prefix.nil?
+ session.boot(mode: as)
+ session.print(suffix) unless suffix.nil?
+ end
+
def self.start(cartridge, session)
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(suffix) unless suffix.nil?
- session.print("\n")
- end
+ boot(cartridge, session, prefix, suffix)
+
+ session.print("\n") if Logic::Helpers::Hash.fetch(cartridge, %i[behaviors boot instruction])
- prompt = build_prompt(Logic::Helpers::Hash.fetch(cartridge, %i[interfaces repl prompt]))
+ prompt = self.prompt(cartridge)
Pry.config.prompt = Pry::Prompt.new(
'REPL',
@@ -40,7 +48,8 @@ module NanoBot
Pry.start
end
- def self.build_prompt(prompt)
+ def self.prompt(cartridge)
+ prompt = Logic::Helpers::Hash.fetch(cartridge, %i[interfaces repl prompt])
result = ''
if prompt.is_a?(Array)