From 3c23785b4645041f2c15d6e238df7375ecad8c72 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:19:50 -0700 Subject: [PATCH] make syntax highlighting colors configurable Read the keyword, literal, enclosed, and error colors from config :sql, :syntax_colors with Application.compile_env, falling back to the current IO.ANSI defaults. The reset sequence stays fixed. Fixes #26 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019wSaUMZrtm6XSzwEcxavkv --- CHANGELOG.md | 5 +++++ README.md | 12 ++++++++++++ lib/format.ex | 8 ++++---- lib/inspect.ex | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b69898..9432695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ # Changelog +## Unreleased + +### Enhancement + - Syntax highlighting colors are configurable with `config :sql, :syntax_colors`. + ## v0.6.0 (2026-10-06) ### Enhancement diff --git a/README.md b/README.md index 912b0a0..6f52d4f 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,18 @@ end [%User{id: 1, email: "john@example.com"}, %User{id: 2, email: "jane@example.com"}] ``` +## Syntax highlighting + +Override keyword, literal, enclosed, and error colors in `config.exs`: + +```elixir +config :sql, :syntax_colors, + keyword: IO.ANSI.magenta(), + literal: IO.ANSI.yellow(), + enclosed: IO.ANSI.green(), + error: IO.ANSI.red() +``` + ## Compile time warning Run `mix sql.get` to generate your `sql.lock` file for error reporting. diff --git a/lib/format.ex b/lib/format.ex index 9d92a07..c46f314 100644 --- a/lib/format.ex +++ b/lib/format.ex @@ -5,11 +5,11 @@ defmodule SQL.Format do @moduledoc false @moduledoc since: "0.4.0" - @error IO.ANSI.red() + @error Application.compile_env(:sql, [:syntax_colors, :error], IO.ANSI.red()) @reset IO.ANSI.reset() - @keyword IO.ANSI.magenta() - @literal IO.ANSI.yellow() - @enclosed IO.ANSI.green() + @keyword Application.compile_env(:sql, [:syntax_colors, :keyword], IO.ANSI.magenta()) + @literal Application.compile_env(:sql, [:syntax_colors, :literal], IO.ANSI.yellow()) + @enclosed Application.compile_env(:sql, [:syntax_colors, :enclosed], IO.ANSI.green()) @compile {:inline, indention: 3, newline: 2, pad: 1, keyword: 2, color: 3} diff --git a/lib/inspect.ex b/lib/inspect.ex index fafd56d..acf843d 100644 --- a/lib/inspect.ex +++ b/lib/inspect.ex @@ -4,7 +4,7 @@ defmodule SQL.Inspect do @moduledoc false - @error IO.ANSI.red() + @error Application.compile_env(:sql, [:syntax_colors, :error], IO.ANSI.red()) @reset IO.ANSI.reset() defimpl Inspect, for: SQL do