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