Class: Bovem::Console

Overview

This is a text utility wrapper console I/O.

Constant Summary

Constants included from Bovem::ConsoleMethods::Logging

Bovem::ConsoleMethods::Logging::DEFAULT_STATUSES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Bovem::ConsoleMethods::Interactions

#read, #task

Methods included from Bovem::ConsoleMethods::Logging

#begin, #debug, #error, #fatal, #get_banner, #info, #progress, #status, #warn, #write, #write_banner_aligned

Methods included from Bovem::ConsoleMethods::Output

#emphasize, #format, #format_right, #indent, #reset_indentation, #set_indentation, #with_indentation, #wrap

Methods included from Bovem::ConsoleMethods::StyleHandling

#replace_markers

Constructor Details

#initializeConsole

Initializes a new Console.



705
706
707
708
709
# File 'lib/bovem/console.rb', line 705

def initialize
  @indentation = 0
  @indentation_string = " "
  @i18n = Bovem::I18n.new(root: "bovem.console", path: Bovem::Application::LOCALE_ROOT)
end

Instance Attribute Details

#i18nI18n (readonly)

Returns A i18n helper.

Returns:

  • (I18n)

    A i18n helper.



688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/bovem/console.rb', line 688

class Console
  attr_accessor :indentation, :indentation_string
  attr_reader :i18n

  include Bovem::ConsoleMethods::StyleHandling
  include Bovem::ConsoleMethods::Output
  include Bovem::ConsoleMethods::Logging
  include Bovem::ConsoleMethods::Interactions

  # Returns a unique instance for Console.
  #
  # @return [Console] A new instance.
  def self.instance
    @instance ||= Bovem::Console.new
  end

  # Initializes a new Console.
  def initialize
    @indentation = 0
    @indentation_string = " "
    @i18n = Bovem::I18n.new(root: "bovem.console", path: Bovem::Application::LOCALE_ROOT)
  end

  # Get the width of the terminal.
  #
  # @return [Fixnum] The current width of the terminal. If not possible to retrieve the width, it returns `80.
  def line_width
    require "io/console" unless defined?($stdin.winsize)
    $stdin.winsize[1]
  rescue
    80
  end
end

#indentationFixnum

Returns Current indentation width.

Returns:

  • (Fixnum)

    Current indentation width.



688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/bovem/console.rb', line 688

class Console
  attr_accessor :indentation, :indentation_string
  attr_reader :i18n

  include Bovem::ConsoleMethods::StyleHandling
  include Bovem::ConsoleMethods::Output
  include Bovem::ConsoleMethods::Logging
  include Bovem::ConsoleMethods::Interactions

  # Returns a unique instance for Console.
  #
  # @return [Console] A new instance.
  def self.instance
    @instance ||= Bovem::Console.new
  end

  # Initializes a new Console.
  def initialize
    @indentation = 0
    @indentation_string = " "
    @i18n = Bovem::I18n.new(root: "bovem.console", path: Bovem::Application::LOCALE_ROOT)
  end

  # Get the width of the terminal.
  #
  # @return [Fixnum] The current width of the terminal. If not possible to retrieve the width, it returns `80.
  def line_width
    require "io/console" unless defined?($stdin.winsize)
    $stdin.winsize[1]
  rescue
    80
  end
end

#indentation_stringString

Returns The string used for indentation.

Returns:

  • (String)

    The string used for indentation.



688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/bovem/console.rb', line 688

class Console
  attr_accessor :indentation, :indentation_string
  attr_reader :i18n

  include Bovem::ConsoleMethods::StyleHandling
  include Bovem::ConsoleMethods::Output
  include Bovem::ConsoleMethods::Logging
  include Bovem::ConsoleMethods::Interactions

  # Returns a unique instance for Console.
  #
  # @return [Console] A new instance.
  def self.instance
    @instance ||= Bovem::Console.new
  end

  # Initializes a new Console.
  def initialize
    @indentation = 0
    @indentation_string = " "
    @i18n = Bovem::I18n.new(root: "bovem.console", path: Bovem::Application::LOCALE_ROOT)
  end

  # Get the width of the terminal.
  #
  # @return [Fixnum] The current width of the terminal. If not possible to retrieve the width, it returns `80.
  def line_width
    require "io/console" unless defined?($stdin.winsize)
    $stdin.winsize[1]
  rescue
    80
  end
end

Class Method Details

.instanceConsole

Returns a unique instance for Console.

Returns:



700
701
702
# File 'lib/bovem/console.rb', line 700

def self.instance
  @instance ||= Bovem::Console.new
end

Instance Method Details

#line_widthFixnum

Get the width of the terminal.

Returns:

  • (Fixnum)

    The current width of the terminal. If not possible to retrieve the width, it returns `80.



714
715
716
717
718
719
# File 'lib/bovem/console.rb', line 714

def line_width
  require "io/console" unless defined?($stdin.winsize)
  $stdin.winsize[1]
rescue
  80
end