Sha256: 0fc07d89bd1479b29c4c63b4d77b5390be6d10f49811f7742b1fd47f95865340

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require "readline"

module Tr3llo
  module Controller
    extend self

    def start(init_command)
      Readline.completion_append_character = " "
      Readline.completion_proc = lambda { |buffer|
        Command.generate_suggestions(buffer, Readline.line_buffer)
      }

      interface = Application.fetch_interface!()

      if init_command && init_command != ""
        init_commands = init_command.split(";")
        init_commands.each do |cmd|
          interface.puts("Executing " + Utils.format_highlight(cmd) + " command")
          execute_command!(cmd)
        end
      end

      loop do
        status_line = determine_status_line()
        command_buffer = Readline.readline(status_line, true)
        Command::Exit.execute() if command_buffer.nil?

        execute_command!(command_buffer)
      end
    rescue Interrupt
      Command::Exit.execute()
    end

    private

    def determine_status_line()
      program_name = ["\e[15;48;5;27m 3llo \e[0m"]
      board_name =
        begin
          ["\e[45m #{Application.fetch_board!().name} \e[0m"]
        rescue BoardNotSelectedError
          []
        end

      (program_name + board_name + [""]).join(" > ")
    end

    def execute_command!(command_buffer)
      Tr3llo::Command.execute(command_buffer.strip())
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
3llo-1.3.1 lib/3llo/controller.rb
3llo-1.3.1.pre.rc.0 lib/3llo/controller.rb
3llo-1.2.0 lib/3llo/controller.rb