123456789_123456789_123456789_123456789_123456789_

Class: IRB::Command::Base

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(irb_context) ⇒ Base

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 82

def initialize(irb_context)
  @irb_context = irb_context
end

Class Method Details

.category(category = nil)

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 19

def category(category = nil)
  @category = category if category
  @category || "No category"
end

.description(description = nil)

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 24

def description(description = nil)
  @description = description if description
  @description || "No description provided."
end

.doc_dialog_content(name, width)

Returns formatted lines for display in the doc dialog popup.

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 41

def doc_dialog_content(name, width)
  lines = []
  lines << Color.colorize(name, [:BOLD, :BLUE]) + Color.colorize(" (command)", [:CYAN])
  lines << ""
  lines.concat(wrap_lines(description, width))
  if help_message
    lines << ""
    lines.concat(wrap_lines(help_message, width))
  end
  lines
end

.execute(irb_context, arg)

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 34

def execute(irb_context, arg)
  new(irb_context).execute(arg)
rescue CommandArgumentError => e
  puts e.message
end

.help_message(help_message = nil)

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 29

def help_message(help_message = nil)
  @help_message = help_message if help_message
  @help_message
end

.highlight(text) (private)

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 55

def highlight(text)
  Color.colorize(text, [:BOLD, :BLUE])
end

.wrap_lines(text, width) (private)

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 59

def wrap_lines(text, width)
  text.lines.flat_map do |line|
    line = line.chomp
    next [''] if line.empty?
    next [line] if line.length <= width

    indent = line[/\A\s*/]
    parts = line.strip.split(/(\s+)/)
    result = []
    current = indent.dup
    parts.each do |part|
      if current != indent && current.length + part.length > width
        result << current.rstrip
        current = indent.dup
      end
      current << part unless current == indent && part.match?(/\A\s+\z/)
    end
    result << current.rstrip unless current == indent
    result
  end
end

Instance Attribute Details

#irb_context (readonly)

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 86

attr_reader :irb_context

Instance Method Details

#execute(arg)

[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 88

def execute(arg)
  #nop
end