1212# ' @section Usage:
1313# '
1414# ' Type outgoing messages and hit return to send.
15- # ' Incoming messages are prefixed by \code{>}.
15+ # '
16+ # ' The timestamps of outgoing messages are prefixed by \code{>} and that of
17+ # ' incoming messages by \code{<}.
1618# '
1719# ' \code{:q} is the command to quit.
1820# '
@@ -34,20 +36,19 @@ messenger <- function(url) {
3436 close(sock )
3537 invisible ()
3638 })
37- cat(" \0 14 " , file = stdout())
39+ cat(" \n " , file = stdout())
3840 intro <- unlist(strsplit(" nanonext messenger" , " " ))
3941 for (i in seq_along(intro )) {
4042 cat(" \r " , `length<-`(intro , i ), sep = " " , file = stdout())
4143 Sys.sleep(0.02 )
4244 }
4345 cat(sprintf(" \n | url: %s\n " , url ), file = stdout())
44- s <- .Call(rnng_send , sock , writeBin(" :c " , raw()), 0L )
46+ cat(" | connecting... " , file = stderr())
47+ s <- .Call(rnng_send , sock , writeBin(" :c " , raw()), 2000L )
4548 if (is.integer(s )) {
46- cat(sprintf(" | peer offline: %s\n " , format.POSIXct(Sys.time())),
47- file = stderr())
49+ cat(sprintf(" \r | peer offline: %s\n " , format.POSIXct(Sys.time())), file = stderr())
4850 } else {
49- cat(sprintf(" | peer online: %s\n " , format.POSIXct(Sys.time())),
50- file = stderr())
51+ cat(sprintf(" \r | peer online: %s\n " , format.POSIXct(Sys.time())), file = stderr())
5152 }
5253 cat(" type your message:\n " , file = stdout())
5354 repeat {
@@ -57,10 +58,11 @@ messenger <- function(url) {
5758 rdata <- writeBin(object = data , con = raw())
5859 s <- .Call(rnng_send , sock , rdata , 0L )
5960 if (is.integer(s )) {
60- cat(sprintf(" | peer offline: message not sent > %s\n " , format.POSIXct(Sys.time())),
61+ cat(sprintf(" %*s > not sent: peer offline: %s\n " , nchar( data ), " " , format.POSIXct(Sys.time())),
6162 file = stderr())
6263 } else {
63- cat(sprintf(" > %s\n " , format.POSIXct(Sys.time())), file = stdout())
64+ cat(sprintf(" %*s > %s\n " , nchar(data ), " " , format.POSIXct(Sys.time())),
65+ file = stdout())
6466 }
6567 }
6668
0 commit comments