File: irb.rb

package info (click to toggle)
ruby-bio 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,480 kB
  • ctags: 9,428
  • sloc: ruby: 74,117; xml: 3,383; makefile: 17; perl: 13; sh: 1
file content (94 lines) | stat: -rw-r--r-- 2,280 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
# = bio/shell/irb.rb - CUI for the BioRuby shell
#
# Copyright::   Copyright (C) 2006
#               Toshiaki Katayama <k@bioruby.org>
# License::     The Ruby License
#
#

module Bio::Shell

  class Irb

    def initialize
      require 'irb'
      begin
        require 'irb/completion'
        Bio::Shell.cache[:readline] = true
      rescue LoadError
        Bio::Shell.cache[:readline] = false
      end
      IRB.setup(nil)
      setup_irb
      start_irb
    end

    def start_irb
      Bio::Shell.cache[:irb] = IRB::Irb.new

      # needed for method completion
      IRB.conf[:MAIN_CONTEXT] = Bio::Shell.cache[:irb].context

      # store binding for evaluation
      Bio::Shell.cache[:binding] = IRB.conf[:MAIN_CONTEXT].workspace.binding

      # overwrite gets to store history with time stamp
      io = IRB.conf[:MAIN_CONTEXT].io
      io.class.class_eval do
        alias_method :irb_original_gets, :gets
      end

      def io.gets
        line = irb_original_gets
        if line
          Bio::Shell.store_history(line)
        end
        return line
      end

      if File.exist?("./config/boot.rb")
        require "./config/boot"
        require "./config/environment"
        #require 'commands/console'
      end
    end

    def setup_irb
      # set application name
      IRB.conf[:AP_NAME] = 'bioruby'

      # change prompt for bioruby
      $_ = Bio::Shell.colors
      IRB.conf[:PROMPT][:BIORUBY_COLOR] = {
        :PROMPT_I => "bio#{$_[:ruby]}ruby#{$_[:none]}> ",
        :PROMPT_S => "bio#{$_[:ruby]}ruby#{$_[:none]}%l ",
        :PROMPT_C => "bio#{$_[:ruby]}ruby#{$_[:none]}+ ",
        :RETURN   => "  ==> %s\n"
      }
      IRB.conf[:PROMPT][:BIORUBY] = {
        :PROMPT_I => "bioruby> ",
        :PROMPT_S => "bioruby%l ",
        :PROMPT_C => "bioruby+ ",
        :RETURN   => "  ==> %s\n"
      }
      if Bio::Shell.config[:color]
        IRB.conf[:PROMPT_MODE] = :BIORUBY_COLOR
      else
        IRB.conf[:PROMPT_MODE] = :BIORUBY
      end

      # echo mode (uncomment to off by default)
      #IRB.conf[:ECHO] = Bio::Shell.config[:echo] || false

      # irb/input-method.rb >= v1.5 (not in 1.8.2)
      #IRB.conf[:SAVE_HISTORY] = 100000

      # not nicely works
      #IRB.conf[:AUTO_INDENT] = true
    end

  end # Irb

end