Class: ColorWish
- Inherits:
-
Djinni::Wish
- Object
- Djinni::Wish
- ColorWish
- Defined in:
- lib/zoom/wish/color_wish.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #description ⇒ Object
- #execute(args, djinni_env = {}) ⇒ Object
-
#initialize ⇒ ColorWish
constructor
A new instance of ColorWish.
- #tab_complete(input, djinni_env = {}) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ ColorWish
Returns a new instance of ColorWish.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/zoom/wish/color_wish.rb', line 51 def initialize @colors = [ "black", "blue", "cyan", "default", "green", "magenta", "red", "white", "yellow", "light_black", "light_blue", "light_cyan", "light_green", "light_magenta", "light_red", "light_white", "light_yellow", "on_black", "on_blue", "on_cyan", "on_green", "on_magenta", "on_red", "on_white", "on_yellow", "on_light_black", "on_light_blue", "on_light_cyan", "on_light_green", "on_light_magenta", "on_light_red", "on_light_white", "on_light_yellow" ] @fields = { "filename" => "Configure filename color (default: green)", "lineno" => "Configure line number color (default: white)", "match" => "Configure match color (default: black.on_white)", "off" => "Turn off colorized output", "on" => "Turn on colorized output (default)", "tag" => "Configure tag color (default: red)" } end |
Instance Method Details
#aliases ⇒ Object
4 5 6 |
# File 'lib/zoom/wish/color_wish.rb', line 4 def aliases return ["color"] end |
#description ⇒ Object
8 9 10 |
# File 'lib/zoom/wish/color_wish.rb', line 8 def description return "Configure colors" end |
#execute(args, djinni_env = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/zoom/wish/color_wish.rb', line 12 def execute(args, djinni_env = {}) f, found, c = args.rpartition(" ") if (f.include?(" ")) usage return end config = djinni_env["config"] if (found.empty?) f = c case f when "off" config.no_hilight when "on" config.hilight else usage end return end case f when "off", "on" usage else c.split(".").each do |color| if (!@colors.include?(color)) puts("Invalid color: #{color}") return end end config.send("set_color_#{f}", c) end end |
#tab_complete(input, djinni_env = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/zoom/wish/color_wish.rb', line 99 def tab_complete(input, djinni_env = {}) f, found, c = input.rpartition(" ") return [{}, "", ""] if (f.include?(" ")) if (found.empty?) f = c completions = @fields.select do |field, desc| field.downcase.start_with?(f.downcase) end append = " " append = "" if (f.start_with?("o")) return [completions, f, append] else case f when "off", "on" return [{}, "", ""] else last = c.rpartition(".")[-1] completions = Hash.new @colors.select do |color| color.downcase.start_with?(last.downcase) end.each do |color| completions[color] = "" end return [completions, last, ""] end end end |
#usage ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/zoom/wish/color_wish.rb', line 133 def usage puts("#{aliases.join(", ")} <field> [color]") puts(" #{description}.") puts puts("FIELDS") @fields.each do |field, desc| puts(" #{field}") end puts puts("COLORS") @colors.each do |color| puts(" #{color}") end end |