Nicer ansi rendering

This commit is contained in:
Roberto Alsina 2024-08-07 20:47:02 -03:00
parent 9824431317
commit b43501da98
2 changed files with 7 additions and 1 deletions

View File

@ -4,6 +4,7 @@ require "./formatter"
require "./rules" require "./rules"
require "./styles" require "./styles"
require "./tartrazine" require "./tartrazine"
# These are Lexer actions. When a rule matches, it will # These are Lexer actions. When a rule matches, it will
# perform a list of actions. These actions can emit tokens # perform a list of actions. These actions can emit tokens
# or change the state machine. # or change the state machine.

View File

@ -44,7 +44,12 @@ module Tartrazine
theme.styles.has_key?(parent) theme.styles.has_key?(parent)
}] }]
end end
text.colorize(*rgb(s.color)).back(*rgb(s.background)).to_s colorized = text.colorize(*rgb(s.color))
# Intentionally not setting background color
colorized.mode(:bold) if s.bold
colorized.mode(:italic) if s.italic
colorized.mode(:underline) if s.underline
colorized.to_s
end end
def rgb(c : String?) def rgb(c : String?)