glimr/console/console
Console helper functions
This module contains helper functions meant for streamlining common console output needs like coloring console output, for example.
Types
Values
pub fn blank_line(output: Output, amount: Int) -> Output
Adds an empty line to the output builder. Useful for creating visual spacing between different sections of your console output.
Example
console.output()
|> console.line("Section 1")
|> console.blank_line(1)
|> console.line("Section 2")
|> console.print()
pub fn error(output: String) -> String
Helper function to color console output. Meant to be used with the io.print or io.println functions. This helper colors output using the terminal’s red color.
Example
io.println(console.error("This message is red"))
// or only have part of the message in red:
io.println("Hello, " <> console.error("Gleam users!"))
pub fn line(output: Output, message: String) -> Output
Adds a line of text to the output builder. Lines are printed in the order they are added. Use this for plain text without any color formatting applied.
Example
console.output()
|> console.line("First line")
|> console.line("Second line")
|> console.print()
pub fn line_error(output: Output, message: String) -> Output
Adds a line colored red (error) to the output. This is a shorthand for line(output, error(message)) and is useful for displaying error messages.
Example
console.output()
|> console.line_error("Failed to write file")
|> console.print()
pub fn line_success(output: Output, message: String) -> Output
Adds a line colored green (success) to the output. This is a shorthand for line(output, success(message)) and is useful for indicating successful operations.
Example
console.output()
|> console.line_success("File created successfully!")
|> console.print()
pub fn line_warning(output: Output, message: String) -> Output
Adds a line colored yellow (warning) to the output. This is a shorthand for line(output, warning(message)) and is useful for displaying warning messages.
Example
console.output()
|> console.line_warning("File already exists, skipping")
|> console.print()
pub fn output() -> Output
Creates a new Output builder with padding enabled by default. Use with line(), blank_line(), and print() to build and display multi-line console output with consistent formatting.
Example
console.output()
|> console.line("Processing files...")
|> console.line_success("Done!")
|> console.print()
pub fn print(output: Output) -> Nil
Prints the output to the console. If padded is true, blank lines are printed before and after the content for visual separation from other terminal output.
Example
console.output()
|> console.line("Hello, world!")
|> console.print()
pub fn success(output: String) -> String
Helper function to color console output. Meant to be used with the io.print or io.println functions. This helper colors output using the terminal’s green color.
Example
io.println(console.success("This message is green"))
// or only have part of the message in green:
io.println("Hello, " <> console.success("Gleam users!"))
pub fn unpadded(output: Output) -> Output
Disables padding (blank lines before/after) on the output. By default, output is padded with blank lines when printed. Use this when you want output without extra spacing.
Example
console.output()
|> console.unpadded()
|> console.line("No blank lines around this")
|> console.print()
pub fn warning(output: String) -> String
Helper function to color console output. Meant to be used with the io.print or io.println functions. This helper colors output using the terminal’s yellow color.
Example
io.println(console.warning("This message is yellow"))
// or only have part of the message in yellow:
io.println("Hello, " <> console.warning("Gleam users!"))