Skip to content

Commit 74b3dc6

Browse files
committedFeb 5, 2010
useable with command line options
1 parent abea8f4 commit 74b3dc6

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed
 

‎README.rdoc

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
snail is an interactive IRC client in an early phase of development.
44
Nothing to see here, move along!
55

6+
= usage
7+
8+
see
9+
ruby bin/snail.rb -h
10+
11+
or have a .snail.config in your home directory
12+
that looks like this:
13+
server:
14+
- host
15+
- port
16+
user: yourusername
17+
password: yourpassword
18+
19+
The options are not optional...
20+
Oh, and after the connection registration, you're on your own
21+
when it comes to the IRC protocol.
22+
623
== Copyright
724

825
Copyright (c) 2010 sMAshdot. See LICENSE for details.

‎bin/snail.rb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#! /usr/bin/env ruby
2+
require 'rubygems'
3+
require 'user-choices'
4+
require 'lib/snail.rb'
5+
6+
class Snail < UserChoices::Command
7+
include UserChoices
8+
9+
def add_sources(builder)
10+
builder.add_source(CommandLineSource, :usage,
11+
"Usage ruby #{$0} [options] host port",
12+
"Connect to IRC.")
13+
builder.add_source(EnvironmentSource, :with_prefix, "snail_")
14+
builder.add_source(YamlConfigFileSource, :from_file, ".snail.config")
15+
end
16+
17+
def add_choices(builder)
18+
builder.add_choice(:server, :length => 2) { |cl|
19+
cl.uses_arglist
20+
}
21+
builder.add_choice(:user) { |cl|
22+
cl.uses_option("-u", "--user NAME", "Your name.")
23+
}
24+
builder.add_choice(:password) { |cl|
25+
cl.uses_option("-p", "--password PASS", "Your password.")
26+
}
27+
end
28+
29+
def postprocess_user_choices
30+
@user_choices[:host] = @user_choices[:server][0]
31+
@user_choices[:port] = @user_choices[:server][1].to_i
32+
end
33+
34+
def execute
35+
c = @user_choices
36+
snail = Client.new(c[:host], c[:port], c[:user], c[:password])
37+
snail.run
38+
end
39+
end
40+
41+
if $0 == __FILE__
42+
Snail.new.execute
43+
end

‎lib/snail.rb

-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@
55

66
require 'snail/connection'
77
require 'snail/client'
8-
9-
snail = Client.new("server", 6666, "username", "pass")
10-
snail.run

‎lib/snail/client.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'observer'
22
require 'thread'
3+
require 'readline'
34

45
class Client
56
def initialize(server, port, user, password)
@@ -21,7 +22,8 @@ def register_connection(user, password)
2122

2223
def get_user_input
2324
loop do
24-
send gets.chomp
25+
line = Readline.readline('', true)
26+
send line
2527
end
2628
end
2729

0 commit comments

Comments
 (0)
Please sign in to comment.