Class: CommandButler::LineDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/command_butler/line_decorator.rb

Class Method Summary collapse

Class Method Details

.decoration(command: command, index: index, current_index: current_index, history: history) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/command_butler/line_decorator.rb', line 3

def self.decoration(command:command, index:index, current_index: current_index, history: history)
  mark = if current_index == index
           "\e[33m" +  " > "
         elsif history
            if history[:result]
              history[:result][:status].success??  "\e[32m" + " o " :  "\e[31m" + " x "
            else
              "\e[32m" + (history[:input].execute?? " o " : " - ")
            end
         else
           "\e[37m" +  "   "
         end
  ret =  "#{index + 1} " + "["+ mark + "\e[0m" + "]"
  if command.command # コマンド
    ret += " " + command.command
  else
    ret += " - "
  end
  ret += " <= chdir to #{command.chdir}" if command.chdir # ディレクトリ移動
  ret
end