I used this for the example if someone want's to play with it: defmodule Colorize do def compare() do """ IO.inspect-IO.innspect IO.inspect-IO.ispect IO.inspect-IO.imspect IO.inspect-IO.inspcet """ |> String.split("\n", trim: true) |> Enum.each(fn x -> [l, r] = String.split(x, "-") compare(l, r) end) end
def compare(expected, expected), do: expected def compare(expected, rendered) do {%ExUnit.Diff{left: {_, _, left}, right: {_, _, right}}, _} = ExUnit.Diff.compute(expected, rendered, :==) IO.puts(["did you mean: ", colorize(left, right)]) end defp colorize([{_, _, added}, r1], [{_, _, deleted}, r2]) do [added(added), deleted(deleted), colorize(r1, r2)] end defp colorize([], []), do: [] defp colorize([{_, _, added} | r1], r2), do: [added(added), colorize(r1, r2)] defp colorize(r1, [{_, _, deleted} | r2]), do: [deleted(deleted), colorize(r1, r2)] defp colorize([{_, _, added}], []), do: added(added) defp colorize([], [{_, _, deleted}]), do: deleted(deleted) defp colorize([h | r1], [h | r2]), do: [h, colorize(r1, r2)] defp added(text), do: IO.ANSI.format([:green_background, text]) defp deleted(text), do: IO.ANSI.format([:red_background, text]) end On Friday, January 21, 2022 at 6:26:09 PM UTC Daniel Kukuła wrote: > I think it can be done on the suggestion only - showing different colors > like here - second example is currently selected but you can see it with > the same background > > On Friday, January 21, 2022 at 11:08:14 AM UTC José Valim wrote: > >> I would love to see how a prototype of this would work. One difficulty to >> keep in mind is that, for a diff to work, you need to show both options >> side by side. And I am not sure if repeating what you typed wrong will be >> helpful. But someone has to play with those ideas before we are sure. :) >> >> On Wed, Jan 19, 2022 at 7:05 PM Daniel Kukuła <danie...@gmail.com> wrote: >> >>> ExUnit has this nice feature that it's showing the differences between >>> the expectation and result in different colors. It would be nice to have >>> something similar with the `did you mean suggestions`. >>> Rationale: >>> It's not the first time that when I made a typo and the compiler suggest >>> the right function/module I'm struggling to see the difference between my >>> code and the suggestions. With short strings it's easy but I got deeply >>> nested modules and sometimes it takes some time to spot the typo. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "elixir-lang-core" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to elixir-lang-co...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/elixir-lang-core/5751b69a-1364-4419-8d8a-273252c9755an%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/elixir-lang-core/5751b69a-1364-4419-8d8a-273252c9755an%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/67614abe-ab76-4a18-a9ab-30c20b4740b1n%40googlegroups.com.