Class: SPSChatCli

Inherits:
SPSChat
  • Object
show all
Defined in:
lib/sps_chat-cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(host: '127.0.0.1', port: '8080', userid: 'user' + (0..1000).to_a.sample.to_s, room: '') ⇒ SPSChatCli

Returns a new instance of SPSChatCli.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sps_chat-cli.rb', line 15

def initialize(host: '127.0.0.1', port: '8080', \
                userid: 'user' + (0..1000).to_a.sample.to_s, room: '')

  super(host: host, port: port, userid: userid, room: room)
  terminate = false
  sleep 1
  print "\r\n"

  loop do

    s = ''

    print "\r> "

    begin

      c = $stdin.getch
      (terminate = true; break) if c == CTRLC

      unless c == BACKSPACE then
        s += c 
        print c
      else
        s.chop!
        print "\r>  " + ' ' * s.length
        print "\r> " + s
      end
    end until c == "\r" or terminate

    break if terminate

    send s
    print "\r" + @userid + '> ' + s + "\n"
  end 
end

Instance Method Details

#onincoming(sender, msg) ⇒ Object



51
52
53
54
55
# File 'lib/sps_chat-cli.rb', line 51

def onincoming(sender, msg)
  s = ''
  print "\r%s> %s\n" % [sender.strip, msg]
  print "\r> "
end