Class: CliMiami::S
- Inherits:
-
Object
- Object
- CliMiami::S
- Defined in:
- lib/cli_miami/say.rb
Class Method Summary collapse
-
.ay(text = '', options = {}) ⇒ Object
By preset [Symbol[… [symbol] Uses defined preset name.
Class Method Details
.ay(text = '', options = {}) ⇒ Object
By preset [Symbol[…
- symbol
-
Uses defined preset name
By options [Hash]… color: => [symbol] See README for ansi color codes bgcolor: => [symbol] See README for ansi color codes style: => [symbol] See README for ansi style codes justify: => [center|ljust|rjust] The type of justification to use padding: => [integer] The maximum string size to justify text in indent: => [integer] The number of characters to indent newline: => [boolean] True if you want a newline after the output overwrite: => [boolean] True if you want the next line to overwrite the current line
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 |
# File 'lib/cli_miami/say.rb', line 29 def self.ay text = '', = {} original_text = text # set default options = { :style => [], :newline => true } # merge preset options if .is_a? Symbol .merge! CliMiami.presets[] elsif preset = .delete(:preset) .merge! CliMiami.presets[preset] end # merge remaining options if .is_a? Hash .merge! end # convert single style into an array for processing if ![:style].is_a? Array [:style] = [[:style]] end # Justify/Padding options if [:justify] && [:padding] text = text.send [:justify], [:padding] end # Set foreground color if [:color] # if bright style is passed, use the bright color variation text = if [:style].delete :bright text.send("bright_#{@options[:color]}") else text.send([:color]) end end # Set background color if [:bgcolor] text = text.send("on_#{@options[:bgcolor]}") end # Apply all styles [:style].each do |style| text = text.send(style) end # Indent if [:indent] text = (' ' * [:indent]) + text end # Flag text to be overwritten by next text written if [:overwrite] text = "#{text}\r" end # Determine if a newline should be used if ![:newline] || [:overwrite] $stdout.print text else $stdout.puts text end # return original text return original_text end |