Anonymous committed 567239c

Added README and example .jabrc files, minor modifications to jab itself.

Comments (0)

Files changed (5)

+jab -- CLI-based Jabber client of/by/for Ruby
+Author:	Chip Camden
+Date:	June, 2010
+jab provides a minimal, text-only, serial (no cursing) XMPP client
+written in Ruby, that uses Ruby as its command language.  jab provides
+methods to handle the common set of chat tasks, but of course you can
+execute any Ruby code within its read-eval-print loop.
+jab binds the execution contect of all evaluated commands commands to a
+proc inside a class named Sandbox.  This means any variables you define
+will not conflict with variables internal to jab, and any classes or
+methods you define will be contained within the Sandbox class.
+To set up your environment each time you start jab, you can place
+commands in a file named ~/.jabrc -- if that file exists, it will be
+executed before jab asks you for input.  Typical commands placed in
+.jabrc include connecting to the XMPP server, defining aliases, selecting
+colors, and user-specific functions.  An example .jabrc file is included
+with this distribution as dot.jabrc, along with two files that it relies
+upon: .jab-aliases (dot.jab-aliases) and .jab-colors (dot.jab-colors).
+You can use this as patterns for creating your own customized jab
+For the list of provided commands, type 'help' at the prompt (:).
+jab supports command history and vi-style editing, using
+Readline.vi_editing_mode.  Whenever a prompt includes a list of possible
+responses, command completion is available by pressing Tab.
+jab does not provide conversation logging, but you can easily accomplish
+that by redirecting output through tee.  jab does not separate multiple,
+simultaneous coonversations, but it does provide visual cues to tell you
+not only who said something but to whom your next line of text will go if
+you don't switch jabs.
+Because XMPP operates asynchronously, you will often receive a message or
+notification while composing a message.  If that confuses you to the
+point of not being able to finish your thought, use Ctrl+U to erase your
+pending input, press Return to get a fresh prompt, and begin again.  An
+empty line is always ignored when entering commands or messages.  If you
+panic and press Ctrl+C, no worries -- the interrupt will be reported to
+you, and you'll get another prompt.
+When you're all done, you can press Ctrl+D (EOF) to exit jab, or use the
+'q' or 'exit' commands.
+chip = ""
+# prompts use a light red
+color /^.*: \z/m , fg(203)
+# status change notifications are grey
+color /^>\S* is .*/ , fg(243)
+# send errors are red
+color /^>\S* ducked your jab.*\Z/m ,fg(red)
+# syntax or execution errors are white on red
+color /^> error .*\Z/m ,bg(red), fg(white)
+# individual jabbers:
+color /^>#{chip}\S* jabs:.*\z/m , fg(32)
+# Read saved aliases
+source "~/.jab-aliases"
+# Here's how we save them
+def save_alias(al=nil, whom=nil, color=nil)
+  nick = al || ask("nickname")
+  if nick
+    who = whom || ask("username")
+    if who
+      cmd = "#{nick} = '#{who}'"
+      eval cmd, $sandbox
+ File.expand_path("~/.jab-aliases"), "a" do |f|
+	f.puts cmd
+      end
+      clr = color || ask("color [none]")
+      if clr && (clr != '')
+        cmd = 'color /^>' + who + '\S* jabs:.*\z/m , fg(' + clr.to_s + ')'
+	eval cmd, $sandbox
+ File.expand_path("~/.jab-colors"), "a" do |f|
+	  f.puts cmd
+	end
+      end
+    end
+  end
+# Set colors, if we can
+if `tput Co`.chomp == '256'
+  source "~/.jab-colors"
+  interject :info, nil, "(no colors)"
+# Connect to my XMPP server
+connect "", "password"
+# Set current status
+status :chat,"Hello Jabberspace!"
 #!/usr/bin/env ruby
 require "rubygems"
 require "readline"
-gem "xmpp4r"
 require "xmpp4r/client"
 require "xmpp4r/roster"
 include Jabber
-$requests = []
-$colors = []
-$op = nil
-$notify = {:errors => true, :info => true, :jabs => true, :status => true, :always => true}
-$accept = :ask
-  Readline.vi_editing_mode
-rescue NotImplementedError
-  interject :info, "vi editing mode not available"
 class Sandbox
   def binding
     ( {}).binding
 def about
-  say "jab version 0.1, by chip camden\n"
+  say "jab version 0.2, by chip camden\n"
   say "\n"
+def getcmd
+  ask('', false, '')
+rescue Interrupt => exc
+  interject :errors, nil, "interrupted"
+  ''
 #Jabber::debug = true
+$requests = []
+$colors = []
+$op = nil
+$notify = {:errors => true, :info => true, :jabs => true, :status => true, :always => true}
+$accept = :ask
 $sandbox =
+  Readline.vi_editing_mode
+rescue NotImplementedError
+  interject :info, "vi editing mode not available"
 source "~/.jabrc", true
 connect if !$client
-while handle_requests && (cmd = ask(''))
+while handle_requests && (cmd = getcmd)
     eval cmd, $sandbox
   rescue SystemExit => exc