From 5c074344d5f50d15df680fa348614e427d5af886 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Fri, 9 Aug 2024 10:30:20 -0300 Subject: [PATCH] Added helper files --- Makefile | 7 +++++++ build_static.sh | 16 ++++++++++++++++ src/formatter.cr | 10 +--------- 3 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 Makefile create mode 100755 build_static.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cc6b324 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +build: $(wildcard src/**/*.cr) $(wildcard lexers/*xml) $(wildcard styles/*xml) shard.yml + shards build -Dstrict_multi_assign -Dno_number_autocast +release: $(wildcard src/**/*.cr) $(wildcard lexers/*xml) $(wildcard styles/*xml) shard.yml + shards build --release +static: $(wildcard src/**/*.cr) $(wildcard lexers/*xml) $(wildcard styles/*xml) shard.yml + shards build --release --static + strip bin/tartrazine diff --git a/build_static.sh b/build_static.sh new file mode 100755 index 0000000..b157b93 --- /dev/null +++ b/build_static.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +docker run --rm --privileged \ + multiarch/qemu-user-static \ + --reset -p yes + +# Build for AMD64 +docker build . -f Dockerfile.static -t tartrazine-builder +docker run -ti --rm -v "$PWD":/app --user="$UID" tartrazine-builder /bin/sh -c "cd /app && rm -rf lib shard.lock && make static" +mv bin/tartrazine bin/tartrazine-static-linux-amd64 + +# Build for ARM64 +docker build . -f Dockerfile.static --platform linux/arm64 -t tartrazine-builder +docker run -ti --rm -v "$PWD":/app --platform linux/arm64 --user="$UID" tartrazine-builder /bin/sh -c "cd /app && rm -rf lib shard.lock && make static" +mv bin/tartrazine bin/tartrazine-static-linux-arm64 diff --git a/src/formatter.cr b/src/formatter.cr index a24f082..de34082 100644 --- a/src/formatter.cr +++ b/src/formatter.cr @@ -44,21 +44,13 @@ module Tartrazine theme.styles.has_key?(parent) }] end - colorized = text.colorize(*rgb(s.color)) + colorized = text.colorize(s.color.try &.colorize) # 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 - - def rgb(c : String?) - return {0_u8, 0_u8, 0_u8} unless c - r = c[0..1].to_u8(16) - g = c[2..3].to_u8(16) - b = c[4..5].to_u8(16) - {r, g, b} - end end class Html < Formatter