Sha256: 317871bc01e20f514819e5d60d7d7397da722d4cce4f0fe1ce8ac34b85860b58

Contents?: true

Size: 1.82 KB

Versions: 22

Compression:

Stored size: 1.82 KB

Contents

module IRT
  class Log

    class Hunk < Array

      attr_reader :header, :color

      def initialize(header)
        @header = header
      end

      def add_line(content, line_no)
        self << [content.chomp, line_no]
      end

      def render(wanted=nil)
        return unless size > 0
        Log.print_border
        render_header
        wanted ||= size
        last(wanted).each do |content, line_no|
          Log.print_border
          render_line(content, line_no)
        end
      end

      def lines_str
        map{|content, line_no| content }.join("\n")
      end

      def last_line_no
        last && last[1]
      end

      def header_name
        @header
      end

      def render_header
        puts IRT.dye("     #{header_name}     ",  "***** #{header_name} *****", color, :bold, :reversed)
      end

      def render_line(content, line_no)
        lcontent = IRT.dye content, color
        lno = IRT.dye(('%3d ' % line_no), color, :reversed)
        puts "#{lno} #{lcontent}"
      end

      def inspect
        %(<#{self.class.name} #{header_name}>)
      end

    end


    class FileHunk < Hunk

      def initialize(header=nil)
        @color = :file_color
        @header = header || IRB.CurrentContext.irb_path
      end

      def header_name
        File.basename(@header)
      end

    end


    class InteractiveHunk < Hunk

      def initialize
        @color = :interactive_color
        @header = IRB.CurrentContext.irb_name
      end

    end


    class InspectHunk < InteractiveHunk

      def initialize
        super
        @color = :inspect_color
      end

      def add_line(content, line_no)
      end

    end

    class BindingHunk < InteractiveHunk

      def initialize
        super
        @color = :binding_color
      end

      def add_line(content, line_no)
      end

    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
irt-1.3.3 lib/irt/hunks.rb
irt-1.3.2 lib/irt/hunks.rb
irt-1.3.1 lib/irt/hunks.rb
irt-1.3.0 lib/irt/hunks.rb
irt-1.2.12 lib/irt/hunks.rb
irt-1.2.11 lib/irt/hunks.rb
irt-1.2.10 lib/irt/hunks.rb
irt-1.2.9 lib/irt/hunks.rb
irt-1.2.8 lib/irt/hunks.rb
irt-1.2.7 lib/irt/hunks.rb
irt-1.2.6 lib/irt/hunks.rb
irt-1.2.5 lib/irt/hunks.rb
irt-1.2.4 lib/irt/hunks.rb
irt-1.2.3 lib/irt/hunks.rb
irt-1.2.2 lib/irt/hunks.rb
irt-1.2.1 lib/irt/hunks.rb
irt-1.2.0 lib/irt/hunks.rb
irt-1.2.0.p02 lib/irt/hunks.rb
irt-1.2.0.p01 lib/irt/hunks.rb
irt-1.1.7 lib/irt/hunks.rb