=== modified file 'ppio.nim' --- ppio.nim 2019-04-04 20:28:23 +0000 +++ ppio.nim 2019-04-04 19:48:08 +0000 @@ -20,6 +20,14 @@ write(stdout, "writeVersion()\n") quit(0) +# proc posixPrintArgs(): void = +# var argc = paramCount() +# for n in countup(1, argc): +# echo " [" & paramStr(n) & "]" +# echo "---" +# for s in commandLineParams(): +# echo " [" & s & "]" + type Args = tuple[ endl: string, @@ -80,7 +88,7 @@ proc copy_data( fd_from:cint, fd_to:cint, - pp_cb:proc(data:string), + # pp_cb:proc(data:string) ): Future[void] = var flags: cint @@ -140,7 +148,6 @@ buffer.setLen(res) when DEBUG_OUT.bool: echo "read[" & $fd.int & "] -> " & repr(buffer) - pp_cb(buffer) writing = true when DEBUG_OUT.bool: echo fmt"reading[{fd_from}]: {reading} writing[{fd_to}]: {writing}" @@ -161,6 +168,8 @@ let remaining = buffer.len - buf_written when DEBUG_OUT.bool: echo fmt"written: {buf_written} remaining: {remaining}" + #var d = cast[cstring](buffer) + #let res = posix.write(fd_to, addr d[buf_written], remaining.cint) let res = posix.write(fd_to, addr buffer[buf_written], remaining.cint) if res < 0: let lastError = osLastError() @@ -194,53 +203,6 @@ return future_result -type DisplayMode = enum - none, - normal, - escaped - -proc pp_writer( - normal: string, - escaped: string, - options: Args, -): proc(data:string) = - proc pp(data: string): void = - var - to_print = "" - dm: DisplayMode = DisplayMode.none - for c in data: - case c - of ' ' .. '~': - if dm != DisplayMode.normal: - to_print.add("\x1b[") - to_print.add(normal) - to_print.add("m") - dm = DisplayMode.normal - to_print.add(c) - else: - if dm != DisplayMode.escaped: - to_print.add("\x1b[") - to_print.add(escaped) - to_print.add("m") - dm = DisplayMode.escaped - to_print.addEscapedChar(c) - # case c: - # of '\0': - # to_print.add("\\0") - # of '\r': - # to_print.add("\\r") - # of '\n': - # to_print.add("\\n") - # of '\t': - # to_print.add("\\t") - # else: - to_print.add("\x1b[0m") - - write(stderr, to_print) - # write(stderr, "\x1b[" & normal & "m" & repr(data) & "\x1b[0m") - return pp - - proc main(): void = var args = posixParseArgs() write(stderr, "args: " & repr(args) & "\n") @@ -292,24 +254,20 @@ # TODO: IO loop here var - rw_stdin: Future[void] = copy_data(0, pipein[1], pp_writer( - args.color_escapes[0], args.color_escapes[1], args, - )) - rw_stdout: Future[void] = copy_data(pipeout[0], 1, pp_writer( - args.color_escapes[2], args.color_escapes[3], args, - )) + rw_stdin: Future[void] = copy_data(0, pipein[1]) + rw_stdout: Future[void] = copy_data(pipeout[0], 1) asyncdispatch.waitFor(rw_stdin or rw_stdout) if rw_stdin.failed: - rw_stdin.read # re-raise + rw_stdin.read # re-reaise if rw_stdout.failed: - rw_stdout.read # re-raise + rw_stdout.read # re-reaise asyncdispatch.waitFor(rw_stdin and rw_stdout) if rw_stdin.failed: - rw_stdin.read # re-raise + rw_stdin.read # re-reaise if rw_stdout.failed: - rw_stdout.read # re-raise + rw_stdout.read # re-reaise var status: cint