Module: Ronin::CLI::Printing::SyntaxHighlighting Private

Includes:
CommandKit::Colors
Included in:
Commands::Highlight, HTTP
Defined in:
lib/ronin/cli/printing/syntax_highlighting.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Mixin that adds syntax highlighting to commands.

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#initialize(**kwargs) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the syntax highlighter.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Since:

  • 2.0.0



37
38
39
40
41
42
43
# File 'lib/ronin/cli/printing/syntax_highlighting.rb', line 37

def initialize(**kwargs)
  super(**kwargs)

  if ansi?
    @syntax_formatter = syntax_formatter
  end
end

#syntax_formatterRouge::Formatters::Terminal256

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The syntax formatter.

Returns:

  • (Rouge::Formatters::Terminal256)

Since:

  • 2.0.0



93
94
95
# File 'lib/ronin/cli/printing/syntax_highlighting.rb', line 93

def syntax_formatter
  Rouge::Formatters::Terminal256.new(syntax_theme)
end

#syntax_lexer(name) ⇒ Class<Rouge::Lexer>?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Looks up the syntax lexer class.

Parameters:

  • name (String)

    The syntax name.

Returns:

  • (Class<Rouge::Lexer>, nil)

Since:

  • 2.0.0



75
76
77
# 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) ⇒ Rouge::Lexer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • filename (String) (defaults to: nil)

    The filename to infer the syntax from.

  • mimetype (String) (defaults to: nil)

    The MIME-type to infer the syntax from.

  • source (String) (defaults to: nil)

    The source code to infer the syntax from.

Returns:

  • (Rouge::Lexer)

Since:

  • 2.0.0



59
60
61
62
63
64
65
# 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_themeRouge::Theme

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The syntax highlighter theme.

Returns:

  • (Rouge::Theme)

Since:

  • 2.0.0



84
85
86
# File 'lib/ronin/cli/printing/syntax_highlighting.rb', line 84

def syntax_theme
  Rouge::Themes::Molokai.new
end