Module: Ripl::Rc::Color

Includes:
U
Defined in:
lib/ripl/rc/color.rb

Defined Under Namespace

Modules: Imp

Class Method Summary collapse

Methods included from U

included

Methods included from SqueezeHistory::Imp

#squeeze_history

Methods included from StripBacktrace::Imp

#cwd, #home, #snip, #strip_backtrace

Methods included from Anchor::Imp

#short_inspect

Methods included from Imp

#black, #blue, #color, #colors, #cyan, #find_color, #green, #magenta, #red, #reset, #white, #yellow

Class Method Details

.format_result(result, display = result.inspect) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ripl/rc/color.rb', line 8

def format_result result, display=result.inspect
  return super(result) if Color.disabled?
  case result
    when String ; U.send(U.colors[String      ]){ display }
    when Numeric; U.send(U.colors[Numeric     ]){ display }
    when Symbol ; U.send(U.colors[Symbol      ]){ display }

    when Array  ; U.send(U.colors[Array       ]){ '['     }  +
                    result.map{ |e| format_result(e) }.join(
                  U.send(U.colors[Array       ]){ ', '    }) +
                  U.send(U.colors[Array       ]){ ']'     }

    when Hash   ; U.send(U.colors[Hash        ]){ '{'     }  +
                    result.map{ |k, v| format_result(k)      +
                  U.send(U.colors[Hash        ]){ '=>'    }  +
                                     format_result(v) }.join(
                  U.send(U.colors[Hash        ]){ ', '    }) +
                  U.send(U.colors[Hash        ]){ '}'     }

    else        ; if color = U.find_color(result)
                  U.send(color){ display }
                  else
                  U.send(U.colors[Object      ]){ display }
                  end
  end
end

.get_error(e, backtrace = e.backtrace) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ripl/rc/color.rb', line 35

def get_error e, backtrace=e.backtrace
  return super if Color.disabled?
  [format_result(e, "#{e.class.to_s}: #{e.message}"),
   backtrace.map{ |b|
     path, rest = File.split(b)
     name, msgs = rest.split(':', 2)
     msg = msgs.sub(/(\d+):/){U.red{$1}+':'}.sub(/`.+?'/){U.green{$&}}

     "#{path+'/'}#{U.yellow{name}}:#{msg}"
   }]
end