clix/send.lua

Thu, 07 Jan 2010 19:50:22 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 07 Jan 2010 19:50:22 +0000
changeset 16
3a1c076d9382
parent 9
clix/message.lua@c1d591488695
child 18
6ad3ea055905
permissions
-rw-r--r--

Rename command 'message'->'send' and add 'receive' to the squishy file

9
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
1 short_opts.i = "interactive";
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
2
0
ae83411a89c9 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 return function (opts, arg)
9
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
4 if (#arg == 0 or opts.help) and not opts.interactive then
0
ae83411a89c9 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 return 0;
ae83411a89c9 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 end
ae83411a89c9 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local function on_connect(conn)
9
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
8 local function send_message(_, text)
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
9 conn:send(verse.message({ to = opts.to, type = opts.type or "chat" }):body(text));
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
10 end
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
11 if opts.interactive then
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
12 -- Fake socket object around stdin
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
13 local stdin = {
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
14 getfd = function () return 0; end;
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
15 dirty = function (self) return false; end;
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
16 settimeout = function () end;
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
17 send = function (_, d) return #d, 0; end;
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
18 close = function () end;
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
19 receive = function (_, patt)
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
20 local data = io.stdin:read(patt);
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
21 io.write(data, patt == "*l" and "\n" or "");
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
22 return data;
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
23 end
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
24 };
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
25 stdin = require "net.server".wrapclient(stdin, "stdin", 0, { onincoming = send_message, ondisconnect = function () end }, "*l");
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
26 else
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
27 send_message(nil, table.concat(arg, " "));
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
28 conn:close();
c1d591488695 clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
29 end
0
ae83411a89c9 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
ae83411a89c9 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 clix_connect(opts, on_connect);
ae83411a89c9 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 end

mercurial