Top Level Namespace

Defined Under Namespace

Modules: Readline, Termtter, Yharian Classes: Array

Instance Method Summary collapse

Instance Method Details

#color(str, value) ⇒ Object



15
16
17
# File 'lib/plugin/stdout.rb', line 15

def color(str, num)
  str.to_s.tosjis
end

#expand_tinyurl(path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/filter/expand-tinyurl.rb', line 12

def expand_tinyurl(path)
  http_class = Net::HTTP
  unless configatron.proxy.host.empty?
    http_class = Net::HTTP::Proxy(configatron.proxy.host,
                                  configatron.proxy.port,
                                  configatron.proxy.user_name,
                                  configatron.proxy.password)
  end
  res = http_class.new('tinyurl.com').head(path)
  res['Location']
end

#fib(n) ⇒ Object



1
# File 'lib/filter/fib.rb', line 1

def fib(n)i=0;j=1;n.times{j=i+i=j};i end

#filter(s) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/termtter.rb', line 53

def filter(s)
  load "filter/#{s}.rb"
rescue LoadError
  raise
else
  Termtter::Client.public_storage[:filters] = []
  Termtter::Client.public_storage[:filters] << s
  true
end

#get_icon_path(s) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/plugin/growl.rb', line 9

def get_icon_path(s)
  cache_file = "%s/%s%s" % [  configatron.plugins.growl.icon_cache_dir, 
                              s.user_screen_name, 
                              File.extname(s.)  ]
  if File.exist?(cache_file) && (File.atime(cache_file) + 24*60*60) > Time.now
    return cache_file
  else
    Thread.new do
      File.open(cache_file, "wb") do |f|
        f << open(URI.escape(s.)).read
      end
    end
    return nil
  end
end

#original_requireObject



65
# File 'lib/termtter.rb', line 65

alias original_require require

#plugin(s) ⇒ Object



49
50
51
# File 'lib/termtter.rb', line 49

def plugin(s)
  require "plugin/#{s}"
end

#puts(str) ⇒ Object



18
19
20
# File 'lib/plugin/stdout.rb', line 18

def puts(str)
  STDOUT.puts(str.tosjis)
end

#quicklook(url) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/plugin/quicklook.rb', line 10

def quicklook(url)
  tmpdir = Pathname.new(configatron.plugins.quicklook.quicklook_tmpdir)
  path   = tmpdir + Pathname.new(url).basename

  Thread.new do
    open(path, 'w') do |f|
      f.write(open(url).read)
    end
    system("qlmanage -p #{path} > /dev/null 2>&1")
  end
end

#require(s) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/termtter.rb', line 66

def require(s)
  if %r|^termtter/(.*)| =~ s
    puts "[WARNING] use plugin '#{$1}' instead of require"
    puts "  Such a legacy .termtter file will not be supported until version 1.0.0"
    s = "plugin/#{$1}"
  end
  original_require s
end

#say(who, what) ⇒ Object

say

String -> String -> IO ()



4
5
6
7
8
# File 'lib/plugin/say.rb', line 4

def say(who, what)
  voices = %w(Alex Bruce Fred Junior Ralph Agnes Kathy Princess Vicki Victoria Albert Bad\ News Bahh Bells Boing Bubbles Cellos Deranged Good\ News Hysterical Pipe\ Organ Trinoids Whisper Zarvox)
  voice = voices[who.hash % voices.size]
  system 'say', '-v', voice, what
end

#translate(text, langpair) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/plugin/translation.rb', line 6

def translate(text, langpair)
  req = Net::HTTP::Post.new('/translate_t')
  req.add_field('Content-Type', 'application/x-www-form-urlencoded')
  req.add_field('User-Agent', 'Mozilla/5.0')
  Net::HTTP.version_1_2 # Proxy に対応してない
  Net::HTTP.start('translate.google.co.jp', 80) {|http|
    response = http.request(req, "langpair=#{langpair}&text=#{URI.escape(text)}")
    doc = Nokogiri::HTML.parse(response.body, nil, 'utf-8')
    return doc.css('#result_box').text
  }
end

#win?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/termtter.rb', line 20

def win?
  RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
end