Skip to content

class Athena::Console::Output::Section
inherits Athena::Console::Output::IO #

A ACON::Output::ConsoleOutput can be divided into multiple sections that can be written to and cleared independently of one another.

Output sections can be used for advanced console outputs, such as displaying multiple progress bars which are updated independently, or appending additional rows to tables.

protected def execute(input : ACON::Input::Interface, output : ACON::Output::Interface) : ACON::Command::Status
  raise "This command may only be used with `ACON::Output::ConsoleOutputInterface`." unless output.is_a? ACON::Output::ConsoleOutputInterface

  section1 = output.section
  section2 = output.section

  section1.puts "Hello"
  section2.puts "World!"
  # Output contains "Hello\nWorld!\n"

  sleep 1

  # Replace "Hello" with "Goodbye!"
  section1.overwrite "Goodbye!"
  # Output now contains "Goodbye\nWorld!\n"

  sleep 1

  # Clear "World!"
  # Output now contains "Goodbye!\n"

  sleep 1

  # Delete the last 2 lines of the first section
  section1.clear 2
  # Output is now empty



.new(io : ::IO, sections : Array(self), verbosity : ACON::Output::Verbosity, decorated : Bool, formatter : ACON::Formatter::Interface)#

View source


#clear(lines : Int32 | Nil = nil) : Nil#

Clears at most lines from self. If lines is nil, all of self is cleared.

View source

#content : String#

Returns the full content string contained within self.

View source

#max_height=(max_height : Int32 | Nil) : Nil#

View source

#overwrite(message : String | Enumerable(String)) : Nil#

Overrides the current content of self with the provided message.

View source

#overwrite(*messages : String) : Nil#

Overrides the current content of self with the provided messages.

View source