module Tco
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
the software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Constants
- VERSION
Public Class Methods
# File lib/tco.rb, line 42 def self.bg(colour, string) decorate string, Style.new(nil, colour) end
# File lib/tco.rb, line 46 def self.bright(string) decorate string, Style.new(nil, nil, true, false) end
# File lib/tco.rb, line 34 def self.colour(fg, bg, string) decorate string, Style.new(fg, bg) end
# File lib/tco.rb, line 88 def self.config @config end
# File lib/tco.rb, line 92 def self.configure c = config yield(c) reconfigure(c) c end
# File lib/tco.rb, line 84 def self.decorate(string, (fg, bg, bright, underline)) @colouring.decorate string, [fg, bg, bright, underline] end
# File lib/tco.rb, line 122 def self.display_palette # TODO: Might be worth sorting, so the pallete is easier to navigate colours = @colouring.palette.colours colours_per_line = (`tput cols`.to_i / 9 - 0.5).ceil c = 0 while c < colours.length do if (c + colours_per_line) < colours.length squares = colours_per_line else squares = colours.length - c end # Prepare the squares for the line square_styles = [] squares.times do square_styles.push [c, @colouring.get_best_font_colour(colours[c]), colours[c]] c += 1 end # The first empty line square_styles.each { |c, fg, bg| print Tco::colour fg, bg, " "*9 } puts # Colour index square_styles.each do |c, fg, bg| print Tco::colour fg, bg, c.to_s.center(9) end puts # Colour value square_styles.each do |c, fg, bg| print Tco::colour fg, bg, bg.to_s.center(9) end puts # Final empty line square_styles.each { |c, fg, bg| print Tco::colour fg, bg, " "*9 } puts end end
# File lib/tco.rb, line 38 def self.fg(colour, string) decorate string, Style.new(colour) end
# File lib/tco.rb, line 58 def self.get_style(style_name) @colouring.get_style style_name end
# File lib/tco.rb, line 104 def self.match_colour(colour_spec) colour = @colouring.get_colour_instance colour_spec @colouring.palette.match_colour colour end
# File lib/tco.rb, line 62 def self.parse(string, default_style) p = Parser.new default_style segments = p.parse string output = "" segments.each do |seg| style = if seg.params[:base_style] @colouring.get_style seg.params[:base_style] else Style.new end style.fg = seg.params[:fg] if seg.params[:fg] style.bg = seg.params[:bg] if seg.params[:bg] style.bright = seg.params[:bright] if seg.params[:bright] style.underline = seg.params[:underline] if seg.params[:underline] output << decorate(seg.to_s, style) end output end
# File lib/tco.rb, line 99 def self.reconfigure(config) @config = config @colouring = Colouring.new config end
# File lib/tco.rb, line 109 def self.show_matching_colour(colour_spec) colour = @colouring.get_colour_instance colour_spec colour_index = @colouring.palette.match_colour colour fg = @colouring.get_best_font_colour colour bg = @colouring.palette.colours[colour_index] puts Tco::colour fg, bg, " "*9 puts Tco::colour fg, bg, colour_index.to_s.center(9) puts Tco::colour fg, bg, bg.to_s.center(9) puts Tco::colour fg, bg, " "*9 end
# File lib/tco.rb, line 54 def self.style(style_name, string) @colouring.decorate(string, @colouring.get_style(style_name)) end
# File lib/tco.rb, line 50 def self.underline(string) decorate string, Style.new(nil, nil, false, true) end