class Athena::Console::Helper::Formatter

Overview

Provides additional ways to format output messages than ACON::Formatter::OutputStyle can do alone, such as:

The provided methods return a String which could then be passed to ACON::Output::Interface#print or ACON::Output::Interface#puts.

Defined in:

helper/formatter.cr

Instance Method Summary

Instance methods inherited from class Athena::Console::Helper

helper_set : ACON::Helper::HelperSet | Nil helper_set, helper_set=(helper_set : ACON::Helper::HelperSet | Nil) helper_set=

Class methods inherited from class Athena::Console::Helper

format_time(span : Time::Span) : String
format_time(seconds : Number) : String
format_time
, remove_decoration(formatter : ACON::Formatter::Interface, string : String) : String remove_decoration, width(string : String) : Int32 width

Instance methods inherited from module Athena::Console::Helper::Interface

helper_set : ACON::Helper::HelperSet | Nil helper_set, helper_set=(helper_set : ACON::Helper::HelperSet | Nil) helper_set=

Instance Method Detail

def format_block(messages : String | Enumerable(String), style : String, large : Bool = false) #

Prints the provided messages in a block formatted according to the provided style, with a total width a bit more than the longest line.

The large options adds additional padding, one blank line above and below the messages, and 2 more spaces on the left and right.

output.puts formatter.format_block({"Error!", "Something went wrong"}, "error", true)

[View source]
def format_section(section : String, message : String, style : String = "info") : String #

Prints the provided message in the provided section. Optionally allows setting the style of the section.

[SomeSection] Here is some message related to that section
output.puts formatter.format_section "SomeSection", "Here is some message related to that section"

[View source]
def truncate(message : String, length : Int, suffix : String = "...") : String #

Truncates the provided message to be at most length characters long, with the optional suffix appended to the end.

message = "This is a very long message, which should be truncated"
truncated_message = formatter.truncate message, 7
output.puts truncated_message # => This is...

If length is negative, it will start truncating from the end.

message = "This is a very long message, which should be truncated"
truncated_message = formatter.truncate message, -4
output.puts truncated_message # => This is a very long message, which should be trunc...

[View source]