Module: CLIMarkdown::Colors
Instance Method Summary collapse
- #c(args) ⇒ Object
- #size_clean ⇒ Object
- #uncolor ⇒ Object
- #uncolor! ⇒ Object
- #wrap(width = 78) ⇒ Object
- #xc(count = 0) ⇒ Object
Instance Method Details
#c(args) ⇒ Object
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mdless/colors.rb', line 51 def c(args) colors = { :reset => 0, # synonym for :clear :x => 0, :bold => 1, :b => 1, :dark => 2, :d => 2, :italic => 3, # not widely implemented :i => 3, :underline => 4, :underscore => 4, # synonym for :underline :u => 4, :blink => 5, :rapid_blink => 6, # not widely implemented :negative => 7, # no reverse because of String#reverse :r => 7, :concealed => 8, :strikethrough => 9, # not widely implemented :black => 30, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36, :white => 37, :on_black => 40, :on_red => 41, :on_green => 42, :on_yellow => 43, :on_blue => 44, :on_magenta => 45, :on_cyan => 46, :on_white => 47, :intense_black => 90, # High intensity, aixterm (works in OS X) :intense_red => 91, :intense_green => 92, :intense_yellow => 93, :intense_blue => 94, :intense_magenta => 95, :intense_cyan => 96, :intense_white => 97, :on_intense_black => 100, # High intensity background, aixterm (works in OS X) :on_intense_red => 101, :on_intense_green => 102, :on_intense_yellow => 103, :on_intense_blue => 104, :on_intense_magenta => 105, :on_intense_cyan => 106, :on_intense_white => 107 } out = [] args.each {|arg| if colors.key? arg out << colors[arg] end } if out.size > 0 "\e[#{out.sort.join(';')}m" else '' end end |
#size_clean ⇒ Object
12 13 14 |
# File 'lib/mdless/colors.rb', line 12 def size_clean self.uncolor.size end |
#uncolor ⇒ Object
4 5 6 |
# File 'lib/mdless/colors.rb', line 4 def uncolor self.gsub(/\e\[[\d;]+m/,'') end |
#uncolor! ⇒ Object
8 9 10 |
# File 'lib/mdless/colors.rb', line 8 def uncolor! self.replace self.uncolor end |
#wrap(width = 78) ⇒ Object
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 |
# File 'lib/mdless/colors.rb', line 16 def wrap(width=78) if self.uncolor =~ /(^([%~] |\s*>)| +[=\-]{5,})/ return self end visible_width = 0 lines = [] line = '' last_ansi = '' line += self.match(/^\s*/)[0].gsub(/\t/,' ') input = self.dup # .gsub(/(\w-)(\w)/,'\1 \2') input.split(/\s+/).each do |word| last_ansi = line.scan(/\e\[[\d;]+m/)[-1] || '' if visible_width + word.size_clean >= width lines << line + xc visible_width = word.size_clean line = last_ansi + word elsif line.empty? visible_width = word.size_clean line = last_ansi + word else visible_width += word.size_clean + 1 line << " " << last_ansi + word end end lines << line + self.match(/\s*$/)[0] + xc if line return lines.join("\n") # .gsub(/\- (\S)/,'-\1') end |
#xc(count = 0) ⇒ Object
47 48 49 |
# File 'lib/mdless/colors.rb', line 47 def xc(count=0) c([:x,:white]) end |