mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-07-04 15:29:25 +00:00
Added --line-numbers for the terminal formatter
This commit is contained in:
@ -2,10 +2,16 @@ require "../formatter"
|
||||
|
||||
module Tartrazine
|
||||
class Ansi < Formatter
|
||||
property? line_numbers : Bool = false
|
||||
|
||||
def format(text : String, lexer : Lexer, theme : Theme) : String
|
||||
output = String.build do |outp|
|
||||
lexer.tokenize(text).each do |token|
|
||||
outp << self.colorize(token[:value], token[:type], theme)
|
||||
lexer.group_tokens_in_lines(lexer.tokenize(text)).each_with_index do |line, i|
|
||||
label = line_numbers? ? "#{i + 1}".rjust(4).ljust(5) : ""
|
||||
outp << label
|
||||
line.each do |token|
|
||||
outp << colorize(token[:value], token[:type], theme)
|
||||
end
|
||||
end
|
||||
end
|
||||
output
|
||||
|
Reference in New Issue
Block a user