class Intar
Constants
- OLDSET
Attributes
catch_exit[RW]
Whether Kernel#exit should be caught.
colour[RW]
histfile[R]
histhid[RW]
Whether to hide entries starting with whitespace.
histmax[RW]
Maximum number of history entries.
pi_suff[RW]
Shell prefix and Pipe suffix
prompt[RW]
sh_pref[RW]
Shell prefix and Pipe suffix
show[RW]
Public Class Methods
new(obj)
click to toggle source
# File lib/intar.rb, line 219 def initialize obj @obj = obj @n = 0 end
Public Instance Methods
hist_add(l)
click to toggle source
# File lib/intar.rb, line 199 def hist_add l return if @histhid and l == /\A[ \t]+/ lst = Readline::HISTORY[-1] if Readline::HISTORY.length > 0 @history.push l unless l == lst end
histfile=(hf)
click to toggle source
# File lib/intar.rb, line 134 def histfile= hf @histfile = hf if @history then @history.finish @histmax @history = History.new @histfile end end
open(obj) { |i| ... }
click to toggle source
# File lib/intar.rb, line 188 def open obj history_file do i = new obj yield i end end
run(obj)
click to toggle source
# File lib/intar.rb, line 195 def run obj open obj do |i| i.run end end
Protected Instance Methods
done()
click to toggle source
# File lib/intar.rb, line 410 def done end
Private Instance Methods
call_system(l, bind)
click to toggle source
# File lib/intar.rb, line 440 def call_system l, bind l.strip! raise Exit if l.empty? eot = "EOT0001" eot.succ! while l[ eot] l = eval "<<#{eot}\n#{l}\n#{eot}", bind, @file system l or raise CmdFailed nil end
colour(*c)
click to toggle source
# File lib/intar.rb, line 265 def colour *c if self.class.colour then s = c.map { |i| "%d" % i }.join ";" "\e[#{s}m" end end
cur_prompt()
click to toggle source
# File lib/intar.rb, line 241 def cur_prompt t = Time.now self.class.prompt.gsub /%(?: \(([^\)]*)\) | ([+-]?[0-9]+(?:\.[0-9]+)?) )?(.)/nx do case $3 when "s" then @obj.to_s when "i" then $1.notempty? ? (@obj.send $1) : @obj.inspect when "n" then "%#$2d" % @n when "t" then t.strftime $1||"%X" when "u" then Etc.getpwuid.name when "h" then Socket.gethostname when "w" then cwd_short when "W" then File.basename cwd_short when "c" then (colour *($1 || $2 || "").split.map { |x| x.to_i }).to_s when ">" then Process.uid == 0 ? "#" : ">" when "%" then $3 else $& end end end
cwd_short()
click to toggle source
# File lib/intar.rb, line 277 def cwd_short r = Dir.pwd h = Etc.getpwuid.dir r[ 0, h.length] == h and r[ 0, h.length] = "~" r end
display(r)
click to toggle source
# File lib/intar.rb, line 318 def display r return if r.nil? show = (self.class.show or return) i = r.inspect if show > 0 then siz, = $stdout.winsize siz *= show siz -= ARROW.length if i.length > siz then i.cut! siz-ELLIPSIS.length i << ELLIPSIS end end i.prepend ARROW puts i end
history_file() { || ... }
click to toggle source
# File lib/intar.rb, line 171 def history_file if @history then yield else @history = History.new @histfile begin yield ensure @history.finish @histmax @history = nil end end end
inherited(sub)
click to toggle source
# File lib/intar.rb, line 156 def inherited sub sub.class_eval { s = superclass @prompt = s.prompt @show = s.show @colour = s.colour @histfile = s.histfile @histmax = s.histmax @histhid = s.histhid @sh_pref = s.sh_pref @pi_suff = s.pi_suff @catch_exit = s.catch_exit } end
pager(doit) { || ... }
click to toggle source
# File lib/intar.rb, line 335 def pager doit if doit then IO.popen ENV[ "PAGER"]||"more", "w" do |pg| begin stdout = $stdout.dup $stdout.reopen pg yield ensure $stdout.reopen stdout end end else yield end end
readline()
click to toggle source
# File lib/intar.rb, line 284 def readline r, @previous = @previous, nil r or @n += 1 cp = cur_prompt loop do begin l = Readline.readline r ? "" : cp rescue Interrupt puts "^C -- #{$!.inspect}" retry end if r then break if l.nil? r << $/ << l break if l.empty? else return if l.nil? next unless l =~ /\S/ r = l break unless l =~ /\+\z/ and $&.length % 2 != 0 end end cp.strip! cp.gsub! /\e\[[0-9]*(;[0-9]*)*m/, "" @file = "#{self.class}/#{cp}" self.class.hist_add r r end
show_exception()
click to toggle source
# File lib/intar.rb, line 423 def show_exception unless $!.to_s.empty? then switchcolour 31, 1 print $! print " " unless $!.to_s =~ /\s\z/ end switchcolour 31, 22 puts "(#{$!.class})" switchcolour 33 bt = $@.dup if bt.length > @cl then bt.pop @cl bt.push bt.pop[ /(.*:\d+):.*/, 1] end puts bt end
switchcolour(*c)
click to toggle source
# File lib/intar.rb, line 272 def switchcolour *c s = colour *c print s if s end
wait_exit()
click to toggle source
# File lib/intar.rb, line 415 def wait_exit c = self.class.catch_exit c and c.times { print "." ; $stdout.flush ; sleep 1 } true rescue Interrupt puts end