Class: Ronin::CLI::Commands::Highlight Private
- Inherits:
-
FileProcessorCommand
- Object
- Core::CLI::Command
- Ronin::CLI::Command
- FileProcessorCommand
- Ronin::CLI::Commands::Highlight
- 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 [] [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
Instance Method Summary collapse
-
#ansi? ⇒ true
private
Indicates that ANSI mode is always enabled.
-
#process_file(file) ⇒ Object
private
Syntax highlights a file.
-
#process_input(input) ⇒ Object
private
Syntax highlights an input stream.
-
#syntax_highlight(input, output: stdout) ⇒ Object
private
Syntax highlights the input stream and prints to the output stream.
Methods included from Printing::SyntaxHighlighting
#initialize, #syntax_formatter, #syntax_lexer, #syntax_lexer_for, #syntax_theme
Methods inherited from FileProcessorCommand
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.
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.
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.
93 94 95 96 97 98 99 100 101 |
# File 'lib/ronin/cli/commands/highlight.rb', line 93 def process_input(input) if [: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.
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 |