Here's an example of a syntax highlighter in elixir, 
can you help me run one in erlang instead?

#!/usr/bin/env elixir

defmodule ChatbotFormatter do
  @default_config %{
    max_width: 100,
    indent: "  ",
    colors: %{
      reset: "\x1b[0m",
      bold: "\x1b[1m",
      italic: "\x1b[3m",
      black: "\x1b[30m",
      red: "\x1b[31m",
      green: "\x1b[32m",
      yellow: "\x1b[33m",
      blue: "\x1b[34m",
      magenta: "\x1b[35m",
      cyan: "\x1b[36m",
      white: "\x1b[37m",
      bg_magenta: "\x1b[45m",
      gray: "\x1b[90m"
    }
  }

  def run(config \\ @default_config) do
    width = get_terminal_width(config)
    
    # Enable raw mode for real-time input handling
    :io.setopts(:standard_io, [mode: :line, echo: false])
    
    process_input(width, config)
  end

  defp process_input(width, config) do
    case IO.getn("", 1) do
      :eof ->
        :ok
      {:error, reason} ->
        IO.puts("Error: #{reason}")
      char ->
        handle_char(char, width, config)
        process_input(width, config)
    end
  end

  defp handle_char(char, width, config) do
    case char do
      "\n" ->
        IO.write("\n")
        process_line(IO.gets(""), width, config)
      _ ->
        IO.write(config.colors.green <> char <> config.colors.reset)
    end
  end

  defp process_line(line, width, config) do
    trimmed_line = String.trim(line)
    cond do
      String.starts_with?(trimmed_line, "```") ->
        process_code_block(trimmed_line, width, config)
      true ->
        format_ai_response(trimmed_line, width, config)
    end
  end

  defp process_code_block(line, width, config) do
    language = Regex.run(~r/```(\w+)/, line)
    |> case do
      [_, lang] -> lang
      _ -> "text"
    end
    
    IO.puts(format_code_block_delimiter(language, config))
    process_code_lines(width, config)
  end

  defp process_code_lines(width, config) do
    case IO.gets("") do
      "```\n" ->
        IO.puts(format_code_block_delimiter("", config))
      line ->
        IO.puts(format_code(line, width, config))
        process_code_lines(width, config)
    end
  end

  defp format_ai_response(line, width, config) do
    content = format_markdown(line, width, config)
    [
      "#{config.colors.magenta}┌#{"─" |> String.duplicate(width - 2)}┐#{config.colors.reset}\n",
      content,
      "#{config.colors.magenta}└#{"─" |> String.duplicate(width - 2)}┘#{config.colors.reset}\n"
    ]
    |> Enum.join("")
    |> IO.write()
  end

  defp format_markdown(line, width, config) do
    line
    |> highlight_markdown(config)
    |> wrap_text(width - 4)
    |> Enum.map(fn l -> 
      "#{config.colors.magenta}│#{config.colors.reset} #{l}#{String.duplicate(" ", max(0, width - String.length(strip_ansi(l)) - 3))}#{config.colors.magenta}│#{config.colors.reset}\n"
    end)
    |> Enum.join()
  end

  defp format_code_block_delimiter(language, config) do
    "#{config.colors.yellow}```#{language}#{config.colors.reset}"
  end

  defp format_code(line, width, config) do
    line
    |> highlight_code(config)
    |> (fn highlighted -> config.indent <> highlighted end).()
    |> wrap_text(width - 4)
    |> Enum.join("\n")
  end

  defp highlight_markdown(line, config) do
    rules = [
      {~r/^(#+)\s+(.+)$/, fn _, hashes, title ->
        "#{config.colors.cyan}#{config.colors.bold}#{hashes} #{title}#{config.colors.reset}"
      end},
      {~r/\*\*(.+?)\*\*/, "#{config.colors.bold}\\1#{config.colors.reset}"},
      {~r/_(.+?)_/, "#{config.colors.italic}\\1#{config.colors.reset}"},
      {~r/`(.+?)`/, "#{config.colors.yellow}\\1#{config.colors.reset}"},
      {~r/\[(.+?)\]\((.+?)\)/, "#{config.colors.blue}[\\1]#{config.colors.reset}#{config.colors.green}(\\2)#{config.colors.reset}"},
      {~r/^(\s*)([-*+])\s+(.+)$/, "\\1#{config.colors.red}\\2#{config.colors.reset} \\3"}
    ]
    apply_highlight_rules(line, rules, config)
  end

  defp highlight_code(line, config) do
    rules = [
      {~r/\b(class|interface|type|enum|constructor|public|private|protected|static|extends|implements|return|if|else|for|while|switch|case|break|continue|try|catch|throw|new|this|super|import|export|as|from|default)\b/, :blue},
      {~r/\b(string|number|boolean|any|void|null|undefined|true|false)\b/, :magenta},
      {~r/"([^"]*)"/, :green},
      {~r/'([^']*)'/, :green},
      {~r/`([^`]*)`/, :green},
      {~r/\b\d+(\.\d+)?\b/, :yellow},
      {~r/[{}()\[\]]/, :cyan},
      {~r/[+\-*\/%=<>!&|^]+/, :red},
      {~r/(\/\/.*)$/, :gray}
    ]
    apply_highlight_rules(line, rules, config)
  end

  defp apply_highlight_rules(text, rules, config) do
    Enum.reduce(rules, text, fn
      {regex, color}, acc when is_atom(color) ->
        Regex.replace(regex, acc, "#{Map.get(config.colors, color)}\\0#{config.colors.reset}")
      {regex, replacement}, acc when is_binary(replacement) ->
        Regex.replace(regex, acc, replacement)
      {regex, fun}, acc when is_function(fun) ->
        Regex.replace(regex, acc, fun)
    end)
  end

  defp wrap_text(text, width) do
    words = String.split(text, ~r/\s+/)
    do_wrap_text(words, width, [])
  end

  defp do_wrap_text([], _, acc), do: Enum.reverse(acc)
  defp do_wrap_text(words, width, acc) do
    {line, rest} = take_line(words, width, [])
    do_wrap_text(rest, width, [Enum.join(line, " ") | acc])
  end

  defp take_line([], _, acc), do: {Enum.reverse(acc), []}
  defp take_line([word | rest], width, acc) do
    new_line = [word | acc]
    new_length = new_line |> Enum.join(" ") |> strip_ansi() |> String.length()
    if new_length <= width do
      take_line(rest, width, new_line)
    else
      {Enum.reverse(acc), [word | rest]}
    end
  end

  defp strip_ansi(string) do
    Regex.replace(~r/\x1b\[[0-9;]*[mG]/, string, "")
  end

  defp get_terminal_width(config) do
    case System.cmd("tput", ["cols"]) do
      {result, 0} -> 
        width = String.trim(result) |> String.to_integer()
        min(width, config.max_width)
      _ -> config.max_width
    end
  end
end

ChatbotFormatter.run() 


Again, so I need the syntax highlighter to be a bit more universal, particularly oriented towards languages such as TypeScript, JavaScript, C++, and Elixir, and also Python. So I wanted to be able to do all of them in a somewhat real-time fashion while being able to handle buffering. And the most important part is that it has to be really performant, and it has to be able to grab any command that you give it. And for example, it could be an IRC chatbot. It could be a system logs viewer. It could be a code review editor    ./chatbot -s settingsfile.yml -m somemodel -p "someprompt blabla | elixir clicolorizer.ex   , I just wanted to be able to take any interactive command line application and be able to, in real time, apply syntax highlighting too. So can you do that for me, please? So first, tell me step by step how the code does, and then rewrite it all in R-Lang in a much better way.