Class: Ronin::CLI::Commands::Highlight Private

Inherits:
FileProcessorCommand show all
Includes:
CommandKit::Pager, Printing::SyntaxHighlighting
Defined in:
lib/ronin/cli/commands/highlight.rb

Overview

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

Syntax highlights a file(s).

Usage

ronin highlight [options] [FILES ...]

Options

-s, --syntax                     Specifies the syntax to highlight
-L, --less                       Display the output in a pager
-h, --help                       Print help information

Arguments

[FILE ...]                       Option file(s) to process

Since:

  • 2.0.0

Instance Method Summary collapse

Methods included from Printing::SyntaxHighlighting

#initialize, #syntax_formatter, #syntax_lexer, #syntax_lexer_for, #syntax_theme

Methods inherited from FileProcessorCommand

#open_file, #run

Instance Method Details

#ansi?true

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.

Indicates that ANSI mode is always enabled.

Returns:

  • (true)

Since:

  • 2.0.0



72
73
74
# File 'lib/ronin/cli/commands/highlight.rb', line 72

def ansi?
  true
end

#process_file(file) ⇒ 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.

Syntax highlights a file.

Parameters:

  • file (String)

Since:

  • 2.0.0



81
82
83
84
85
# File 'lib/ronin/cli/commands/highlight.rb', line 81

def process_file(file)
  @syntax_lexer ||= syntax_lexer_for(filename: file)

  super(file)
end

#process_input(input) ⇒ 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.

Syntax highlights an input stream.

Parameters:

  • input (File, IO)

    The input file or stdin.

Since:

  • 2.0.0



93
94
95
96
97
98
99
100
101
# File 'lib/ronin/cli/commands/highlight.rb', line 93

def process_input(input)
  if options[:less]
    pager do |less|
      syntax_highlight(input, output: less)
    end
  else
    syntax_highlight(input)
  end
end

#syntax_highlight(input, output: stdout) ⇒ 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.

Syntax highlights the input stream and prints to the output stream.

Parameters:

  • input (File, IO)

    The input file or stdin.

  • output (IO) (defaults to: stdout)

    The less output stream or stdout.

Since:

  • 2.0.0



112
113
114
115
116
# File 'lib/ronin/cli/commands/highlight.rb', line 112

def syntax_highlight(input, output: stdout)
  input.each_line do |line|
    output.print(@syntax_formatter.format(@syntax_lexer.lex(line)))
  end
end