class Athena::Console::Output::Section

Overview

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 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

Defined in:

output/section.cr

Constructors

Instance Method Summary

Instance methods inherited from class Athena::Console::Output::IO

io : ::IO io, io=(io : ::IO) io=, to_s(*args, **options)
to_s(*args, **options, &)
to_s

Constructor methods inherited from class Athena::Console::Output::IO

new(io : ::IO, verbosity : ACON::Output::Verbosity | Nil = :normal, decorated : Bool | Nil = nil, formatter : ACON::Formatter::Interface | Nil = nil) new

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

decorated=(decorated : Bool) : Nil decorated=, decorated? : Bool decorated?, formatter : ACON::Formatter::Interface formatter, formatter=(formatter : ACON::Formatter::Interface) : Nil formatter=, print(message : String | Enumerable(String), verbosity : ACON::Output::Verbosity = :normal, output_type : ACON::Output::Type = :normal) : Nil
print(message : _, verbosity : ACON::Output::Verbosity = :normal, output_type : ACON::Output::Type = :normal) : Nil
print(*messages : String) : Nil
print
, puts(message : String | Enumerable(String), verbosity : ACON::Output::Verbosity = :normal, output_type : ACON::Output::Type = :normal) : Nil
puts(message : _, verbosity : ACON::Output::Verbosity = :normal, output_type : ACON::Output::Type = :normal) : Nil
puts(*messages : String) : Nil
puts
, verbosity : ACON::Output::Verbosity verbosity, verbosity=(verbosity : ACON::Output::Verbosity) : Nil verbosity=

Constructor methods inherited from class Athena::Console::Output

new(verbosity : ACON::Output::Verbosity | Nil = :normal, decorated : Bool = false, formatter : ACON::Formatter::Interface | Nil = nil) new

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

decorated=(decorated : Bool) : Nil decorated=, decorated? : Bool decorated?, formatter : ACON::Formatter::Interface formatter, formatter=(formatter : ACON::Formatter::Interface) : Nil formatter=, print(message : String | Enumerable(String), verbosity : ACON::Output::Verbosity = :normal, output_type : ACON::Output::Type = :normal) : Nil print, puts(message : String | Enumerable(String), verbosity : ACON::Output::Verbosity = :normal, output_type : ACON::Output::Type = :normal) : Nil puts, verbosity : ACON::Output::Verbosity verbosity, verbosity=(verbosity : ACON::Output::Verbosity) : Nil verbosity=

Constructor Detail

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

[View source]

Instance Method Detail

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

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


[View source]
def content : String #

Returns the full content string contained within self.


[View source]
def max_height=(max_height : Int32 | Nil) : Nil #

[View source]
def overwrite(message : String | Enumerable(String)) : Nil #

Overrides the current content of self with the provided message.


[View source]
def overwrite(*messages : String) : Nil #

Overrides the current content of self with the provided messages.


[View source]