From f2e638ce3b661b6bc1630ba96e5be32cea1d52cd Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Sat, 10 Aug 2024 16:50:55 -0300 Subject: [PATCH] Require main branch sixteen for now, line-highlight style improvements --- shard.yml | 1 + src/main.cr | 17 +++++++++-------- src/styles.cr | 27 +++++++++++---------------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/shard.yml b/shard.yml index 4fa51e7..34ae058 100644 --- a/shard.yml +++ b/shard.yml @@ -15,6 +15,7 @@ dependencies: github: crystal-china/base58.cr sixteen: github: ralsina/sixteen + branch: main docopt: github: chenkovsky/docopt.cr diff --git a/src/main.cr b/src/main.cr index 515ad49..418f228 100644 --- a/src/main.cr +++ b/src/main.cr @@ -23,12 +23,13 @@ HELP lexer = Tartrazine.lexer("crystal") theme = Tartrazine.theme(ARGV[1]) -formatter = Tartrazine::Json.new -# formatter.standalone = true -# formatter.class_prefix = "hl-" -# formatter.line_number_id_prefix = "ln-" -# formatter.line_numbers = true -# formatter.highlight_lines = [3..7, 20..30] -# formatter.linkable_line_numbers = false -# formatter.wrap_long_lines = false +# formatter = Tartrazine::Json.new +formatter = Tartrazine::Html.new +formatter.standalone = true +formatter.class_prefix = "hl-" +formatter.line_number_id_prefix = "ln-" +formatter.line_numbers = true +formatter.highlight_lines = [3..7, 20..30] +formatter.linkable_line_numbers = false +formatter.wrap_long_lines = false puts formatter.format(File.read(ARGV[0]), lexer, theme) diff --git a/src/styles.cr b/src/styles.cr index 31921a5..4fcf410 100644 --- a/src/styles.cr +++ b/src/styles.cr @@ -12,7 +12,7 @@ module Tartrazine def self.theme(name : String) : Theme begin - return Theme.from_base16(name) + return Theme.from_base16(name) rescue ex : Exception raise ex unless ex.message.try &.includes? "Theme not found" end @@ -111,7 +111,7 @@ module Tartrazine # The color assignments are adapted from # https://github.com/mohd-akram/base16-pygments/ - theme.styles["Background"] = Style.new(color: t["base05"], background: t["base00"]) + theme.styles["Background"] = Style.new(color: t["base05"], background: t["base00"], bold: true) theme.styles["LineHighlight"] = Style.new(color: t["base0D"], background: t["base01"]) theme.styles["Text"] = Style.new(color: t["base05"]) theme.styles["Error"] = Style.new(color: t["base08"]) @@ -175,27 +175,22 @@ module Tartrazine if !theme.styles.has_key?("LineHighlight") theme.styles["LineHighlight"] = Style.new theme.styles["LineHighlight"].background = make_highlight_color(theme.styles["Background"].background) + theme.styles["LineHighlight"].bold = true end theme end # If the color is dark, make it brighter and viceversa def self.make_highlight_color(base_color) - # FIXME: do a proper luminance adjustment in the color class - return nil if base_color.nil? - color = Color.new(base_color.hex) - if base_color.light? - color.r = [(base_color.r - 40), 255].min.to_u8 - color.g = [(base_color.g - 40), 255].min.to_u8 - color.b = [(base_color.b - 40), 255].min.to_u8 - else - color.r = [(base_color.r + 40), 255].min.to_u8 - color.g = [(base_color.g + 40), 255].min.to_u8 - color.b = [(base_color.b + 40), 255].min.to_u8 + if base_color.nil? + # WHo knows + return Color.new(127, 127, 127) + end + if base_color.dark? + return base_color.lighter(0.2) + else + return base_color.darker(0.2) end - # Bug in color, setting rgb doesn't update hex - color.hex = "#{color.r.to_s(16)}#{color.g.to_s(16)}#{color.b.to_s(16)}" - color end end end