Skip to content

Commit fdf75bc

Browse files
committed
Update ansi highligthing
1 parent b400e43 commit fdf75bc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/sql.ex

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,27 @@ defmodule SQL do
219219
end
220220
end
221221

222+
@error IO.ANSI.red()
223+
@reset IO.ANSI.reset()
224+
222225
@doc false
223226
def __inspect__(tokens, context, stack) do
224-
inspect = IO.iodata_to_binary(["\e[0m", "~SQL\"\"\""|[SQL.Format.to_iodata(tokens, context)|~c"\n\"\"\""]])
227+
inspect = IO.iodata_to_binary([@reset, "~SQL\"\"\""|[SQL.Format.to_iodata(tokens, context)|~c"\n\"\"\""]])
225228
case context.errors do
226229
[] -> inspect
227230
errors ->
228231
{:current_stacktrace, [_|t]} = Process.info(self(), :current_stacktrace)
229-
IO.warn([?\n,format_error(errors), IO.iodata_to_binary(["\e[0m", " ~SQL\"\"\""|[SQL.Format.to_iodata(tokens, context, 1)|~c"\n \"\"\""]])], [stack|t])
232+
IO.warn([?\n,format_error(errors), IO.iodata_to_binary([@reset, " ~SQL\"\"\""|[SQL.Format.to_iodata(tokens, context, 1)|~c"\n \"\"\""]])], [stack|t])
230233
inspect
231234
end
232235
end
233236

234237
@doc false
235238
def format_error(errors), do: Enum.group_by(errors, &elem(&1, 2)) |> Enum.reduce([], fn
236-
{k, [{:special, _, _}]}, acc -> [acc|[" the operator \e[31m",k,"\e[0m is invalid, did you mean any of #{__suggest__(k)}\n"]]
237-
{k, [{:special, _, _}|_]=v}, acc -> [acc|[" the operator \e[31m",k,"\e[0m is mentioned #{length(v)} times but is invalid, did you mean any of #{__suggest__(k)}\n"]]
238-
{k, [_]}, acc -> [acc|[" the relation \e[31m",k,"\e[0m does not exist\n"]]
239-
{k, v}, acc -> [acc|[" the relation \e[31m",k,"\e[0m is mentioned #{length(v)} times but does not exist\n"]]
239+
{k, [{:special, _, _}]}, acc -> [acc|[" the operator", @error,k,@reset, " is invalid, did you mean any of #{__suggest__(k)}\n"]]
240+
{k, [{:special, _, _}|_]=v}, acc -> [acc|[" the operator ",@error,k,@reset," is mentioned #{length(v)} times but is invalid, did you mean any of #{__suggest__(k)}\n"]]
241+
{k, [_]}, acc -> [acc|[" the relation ",@error,k,@reset," does not exist\n"]]
242+
{k, v}, acc -> [acc|[" the relation ",@error,k,@reset," is mentioned #{length(v)} times but does not exist\n"]]
240243
end)
241244

242245
@doc false

0 commit comments

Comments
 (0)