Module: Colora

Defined in:
lib/colora.rb,
lib/colora/data.rb,
lib/colora/lines.rb,
lib/colora/configure.rb,
lib/colora/plugs/diff.rb,
lib/colora/plugs/markdown.rb

Defined Under Namespace

Classes: Data, Error, Lines

Constant Summary collapse

VERSION =
'0.2.240119'
Config =
OpenStruct.new
FILTERS =

Filter keys:

%i[quiet green red code comment dupcode dupcomment]

Class Method Summary collapse

Class Method Details

.configure(options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/colora/configure.rb', line 26

def self.configure(options)
  # FILE:
  Config.file = options.file if options.file

  # Options:
  Config.theme = options.theme if options.theme?
  Config.lang  = options.lang if options.lang?
  Config.git   = options.git?
  Config.tab   = options.tab?

  # Filters:
  # Config.quiet=options.quiet? ...
  FILTERS.each{Config[_1]=options.send("#{_1}?")}
end

.run(options = nil) ⇒ Object

Colora.run(options)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/colora.rb', line 6

def self.run(options=nil)
  # Standard libraries:
  require 'ostruct'
  # Gems:
  require 'fuzzystringmatch'
  require 'paint'
  require 'rouge'
  # Colora:
  require_relative 'colora/configure'
  require_relative 'colora/data'
  require_relative 'colora/lines'
  # Plugs:
  require_relative 'colora/plugs/diff'
  require_relative 'colora/plugs/markdown'

  # Configure Colora:
  Colora.configure(options) if options
  # By default, run git-diff:
  Config.git = true if $stdin.tty? && !Config.file

  # Puts Colora::Lines
  Lines.new.each do |line|
    line.gsub!("\t", '') if Config.tab
    puts line
  end
end