Class: Bovem::Console

Inherits:
Object
  • Object
show all
Includes:
Bovem::ConsoleMethods::Interactions, Bovem::ConsoleMethods::Logging, Bovem::ConsoleMethods::Output, Bovem::ConsoleMethods::StyleHandling, Lazier::I18n
Defined in:
lib/bovem/console.rb

Overview

This is a text utility wrapper console I/O.

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.



630
631
632
633
634
# File 'lib/bovem/console.rb', line 630

def initialize
  @indentation = 0
  @indentation_string = " "
  i18n_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
end

Instance Attribute Details

#indentationFixnum

Returns Current indentation width.

Returns:

  • (Fixnum)

    Current indentation width.



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# File 'lib/bovem/console.rb', line 612

class Console
  attr_accessor :indentation
  attr_accessor :indentation_string

  include Lazier::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_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
  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
    begin
      require "io/console" if !defined?($stdin.winsize)
      $stdin.winsize[1]
    rescue
      80
    end
  end
end

#indentation_stringString

Returns The string used for indentation.

Returns:

  • (String)

    The string used for indentation.



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# File 'lib/bovem/console.rb', line 612

class Console
  attr_accessor :indentation
  attr_accessor :indentation_string

  include Lazier::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_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
  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
    begin
      require "io/console" if !defined?($stdin.winsize)
      $stdin.winsize[1]
    rescue
      80
    end
  end
end

Class Method Details

.instanceConsole

Returns a unique instance for Console.

Returns:



625
626
627
# File 'lib/bovem/console.rb', line 625

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.



639
640
641
642
643
644
645
646
# File 'lib/bovem/console.rb', line 639

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