# HG changeset patch # User Matthew Wild # Date 1262893822 0 # Node ID 3a1c076d938261e0a33fe7c8fd94de51af66bb3b # Parent 54314164a2a3529f64697e4e4b30a651f4547b0e Rename command 'message'->'send' and add 'receive' to the squishy file diff -r 54314164a2a3 -r 3a1c076d9382 clix/message.lua --- a/clix/message.lua Thu Jan 07 02:36:52 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -short_opts.i = "interactive"; - -return function (opts, arg) - if (#arg == 0 or opts.help) and not opts.interactive then - return 0; - end - local function on_connect(conn) - local function send_message(_, text) - conn:send(verse.message({ to = opts.to, type = opts.type or "chat" }):body(text)); - end - if opts.interactive then - -- Fake socket object around stdin - local stdin = { - getfd = function () return 0; end; - dirty = function (self) return false; end; - settimeout = function () end; - send = function (_, d) return #d, 0; end; - close = function () end; - receive = function (_, patt) - local data = io.stdin:read(patt); - io.write(data, patt == "*l" and "\n" or ""); - return data; - end - }; - stdin = require "net.server".wrapclient(stdin, "stdin", 0, { onincoming = send_message, ondisconnect = function () end }, "*l"); - else - send_message(nil, table.concat(arg, " ")); - conn:close(); - end - end - clix_connect(opts, on_connect); -end diff -r 54314164a2a3 -r 3a1c076d9382 clix/send.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clix/send.lua Thu Jan 07 19:50:22 2010 +0000 @@ -0,0 +1,32 @@ +short_opts.i = "interactive"; + +return function (opts, arg) + if (#arg == 0 or opts.help) and not opts.interactive then + return 0; + end + local function on_connect(conn) + local function send_message(_, text) + conn:send(verse.message({ to = opts.to, type = opts.type or "chat" }):body(text)); + end + if opts.interactive then + -- Fake socket object around stdin + local stdin = { + getfd = function () return 0; end; + dirty = function (self) return false; end; + settimeout = function () end; + send = function (_, d) return #d, 0; end; + close = function () end; + receive = function (_, patt) + local data = io.stdin:read(patt); + io.write(data, patt == "*l" and "\n" or ""); + return data; + end + }; + stdin = require "net.server".wrapclient(stdin, "stdin", 0, { onincoming = send_message, ondisconnect = function () end }, "*l"); + else + send_message(nil, table.concat(arg, " ")); + conn:close(); + end + end + clix_connect(opts, on_connect); +end diff -r 54314164a2a3 -r 3a1c076d9382 squishy --- a/squishy Thu Jan 07 02:36:52 2010 +0000 +++ b/squishy Thu Jan 07 19:50:22 2010 +0000 @@ -1,4 +1,5 @@ -Module "clix.message" "clix/message.lua" +Module "clix.send" "clix/send.lua" +Module "clix.receive" "clix/receive.lua" Module "clix.version" "clix/version.lua" Main "clix.lua"