Sha256: 97ecd5dcd424e424afc7813d20645fa29f89a7b5c57b540b9aaa3d8a1ee9143c

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

#!/usr/bin/env ruby

require 'blather/client'

#ls
#cd
#cat
#Blather::LOG.level = Logger::DEBUG
module CliHandler
  include EM::Protocols::LineText2

  def ls(node)
    pubsub.node(parse_dir(node)) do |result|
      cur = node.split('/')
      puts
      puts result.items.map { |i| (i.node.split('/') - cur).join('/') }.join("\n")
      start_line
    end
  end

  def cd(node)
    @node = parse_dir(node)
    start_line
  end

  def cat(item)
  end

  def connect(who)
    @who = who
    puts "connected to '#{who}'"
  end

  def exit(_)
    EM.stop
  end

  def initialize
    $stdout.sync = true
    @node = ''
    @who = ''
    start_line
  end

  def start_line
    puts "\n/#{@node}> "
  end

  def receive_line(line)
    return unless line =~ /(connect|exit|ls|cd|cat)\s?(.*)/i
    __send__ $1, $2
  end

  def parse_dir(list)
    return '' if list == '/'
    cur = @node.split('/')
    list.split('/').each { |dir| dir == '..' ? cur.pop : (cur << dir) }
    cur * '/'
  end
end

setup 'echo@jabber.local', 'echo'
pubsub_host 'pubsub.jabber.local'
when_ready { EM.open_keyboard CliHandler }

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
sprsquish-blather-0.4.0 examples/pubsub/cli.rb
sprsquish-blather-0.4.1 examples/pubsub/cli.rb
sprsquish-blather-0.4.2 examples/pubsub/cli.rb
sprsquish-blather-0.4.3 examples/pubsub/cli.rb
sprsquish-blather-0.4.4 examples/pubsub/cli.rb
blather-0.4.7 examples/pubsub/cli.rb
blather-0.4.6 examples/pubsub/cli.rb
blather-0.4.5 examples/pubsub/cli.rb
blather-0.4.4 examples/pubsub/cli.rb
blather-0.4.3 examples/pubsub/cli.rb
blather-0.2.2 examples/pubsub/cli.rb
blather-0.4.1 examples/pubsub/cli.rb
blather-0.4.2 examples/pubsub/cli.rb
blather-0.4.0 examples/pubsub/cli.rb