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.

Todo

Implement progress bars and tables.

protected def execute(input : ACON::Input::Interface, output : ACON::Output::Interface) : ACON::Command::Status
  raise ArgumentError.new "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!"
  section2.clear
  # Output now contains "Goodbye!\n"

  sleep 1

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

  ACON::Command::Status::SUCCESS
end

Constructors#

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

View source

Methods#

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

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

View source

#content #

Returns the full content string contained within self.

View source

#overwrite(message : String) : Nil #

Overrides the current content of self with the provided message.

View source