gsh/evaluator/formatter

The formatter module is responsible for cleaning up and beautifying the raw output emitted by the Gleam compiler and Erlang runtime.

Because GSH executes code by compiling temporary gsh_eval_X.gleam files, the underlying compiler frequently generates noisy “unused variable” warnings and exposes absolute internal file paths. This module intercepts that text stream, purges the noise, rewrites stack traces to simulate a native REPL environment, and applies ANSI syntax highlighting.

Values

pub fn format_error(output: String) -> String

Processes the output of a failed code evaluation (compiler error or runtime crash).

Error Pipeline:

  • Runs the identical warning filter to strip out unrelated noise.
  • Trims whitespace.
  • Passes the resulting string through the hide_internal_path interceptor so the user sees a pristine REPL error trace rather than a filesystem leak.
pub fn format_output(output: String) -> String

Processes the standard output of a successful code evaluation.

Formatting Pipeline:

  • Splits the raw output by line and feeds it through the warning filter.
  • Trims trailing whitespace.
  • Applies dynamic ANSI syntax highlighting via the contour library so returned data structures (like tuples or records) look native to the terminal.
Search Document