module Ronin::CLI::Printing::SyntaxHighlighting

Mixin that adds syntax highlighting to commands.

Public Class Methods

new(**kwargs) click to toggle source

Initializes the syntax highlighter.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments.
Calls superclass method
# File lib/ronin/cli/printing/syntax_highlighting.rb, line 37
def initialize(**kwargs)
  super(**kwargs)

  if ansi?
    @syntax_formatter = syntax_formatter
  end
end

Public Instance Methods

syntax_formatter() click to toggle source

The syntax formatter.

@return [Rouge::Formatters::Terminal256]

# File lib/ronin/cli/printing/syntax_highlighting.rb, line 93
def syntax_formatter
  Rouge::Formatters::Terminal256.new(syntax_theme)
end
syntax_lexer(name) click to toggle source

Looks up the syntax lexer class.

@param [String] name

The syntax name.

@return [Class<Rouge::Lexer>, nil]

# File lib/ronin/cli/printing/syntax_highlighting.rb, line 75
def syntax_lexer(name)
  Rouge::Lexer.find(name)
end
syntax_lexer_for(filename: nil, mimetype: nil, source: nil) click to toggle source

Loads the syntax lexer for the filename, mimetype, or source code.

@param [String] filename

The filename to infer the syntax from.

@param [String] mimetype

The MIME-type to infer the syntax from.

@param [String] source

The source code to infer the syntax from.

@return [Rouge::Lexer]

# File lib/ronin/cli/printing/syntax_highlighting.rb, line 59
def syntax_lexer_for(filename: nil, mimetype: nil, source: nil)
  Rouge::Lexer.guess(
    filename: filename,
    mimetype: mimetype,
    source:   source
  )
end
syntax_theme() click to toggle source

The syntax highlighter theme.

@return [Rouge::Theme]

# File lib/ronin/cli/printing/syntax_highlighting.rb, line 84
def syntax_theme
  Rouge::Themes::Molokai.new
end