Module: CssColorContrast::Cli

Defined in:
lib/css_color_contrast/cli.rb

Constant Summary collapse

<<~BANNER
To calculate the contrast ratio between 2 colors, enter the following command:

  > ratio: color1 color2

For the values of color1 and color2, hexadecimal notation, RGB/HSL/HWB
functions and the extended color keywords are supported.

To finish the program, enter 'exit'.
BANNER

Class Method Summary collapse

Class Method Details



19
20
21
# File 'lib/css_color_contrast/cli.rb', line 19

def self.print_banner
  $stdout.print BANNER
end

.read_commandsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/css_color_contrast/cli.rb', line 23

def self.read_commands
  env = {}

  while line = Readline.readline('> ', true)
    begin
      exit if line.chomp == 'exit'
      func = CommandInterpreter::Parser.parse!(line.chomp, env)
      $stdout.puts func.evaluate
    rescue => e
      puts e
    end
  end
end

.startObject



37
38
39
40
# File 'lib/css_color_contrast/cli.rb', line 37

def self.start
  print_banner
  read_commands
end