diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/msgs.nim | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 4dd134177..3fabf6bbf 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -734,20 +734,22 @@ proc outWriteln*(s: string) = flushFile(stdout) proc msgWriteln*(s: string) = - ## Writes to stdout. If --stdout option is given, writes to stderr instead. + ## Writes to stderr. If --stdout option is given, writes to stdout instead. #if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return if not isNil(writelnHook): writelnHook(s) elif optStdout in gGlobalOptions: - if eStdErr in errorOutputs: - writeLine(stderr, s) - flushFile(stderr) - else: if eStdOut in errorOutputs: writeLine(stdout, s) flushFile(stdout) + else: + if eStdErr in errorOutputs: + writeLine(stderr, s) + # On Windows stderr is fully-buffered when piped, regardless of C std. + when defined(windows): + flushFile(stderr) macro callIgnoringStyle(theProc: typed, first: typed, args: varargs[expr]): stmt = @@ -767,8 +769,9 @@ macro callIgnoringStyle(theProc: typed, first: typed, typ != typTerminalCmd: result.add(arg) -macro callStyledEcho(args: varargs[expr]): stmt = - result = newCall(bindSym"styledEcho") +macro callStyledWriteLineStderr(args: varargs[expr]): stmt = + result = newCall(bindSym"styledWriteLine") + result.add(bindSym"stderr") for arg in children(args[0][1]): result.add(arg) @@ -782,16 +785,18 @@ template styledMsgWriteln*(args: varargs[expr]) = if not isNil(writelnHook): callIgnoringStyle(callWritelnHook, nil, args) elif optStdout in gGlobalOptions: - if eStdErr in errorOutputs: - callIgnoringStyle(writeLine, stderr, args) - flushFile(stderr) - else: if eStdOut in errorOutputs: + callIgnoringStyle(writeLine, stdout, args) + flushFile(stdout) + else: + if eStdErr in errorOutputs: if optUseColors in gGlobalOptions: - callStyledEcho(args) + callStyledWriteLineStderr(args) else: - callIgnoringStyle(writeLine, stdout, args) - flushFile stdout + callIgnoringStyle(writeLine, stderr, args) + # On Windows stderr is fully-buffered when piped, regardless of C std. + when defined(windows): + flushFile(stderr) proc coordToStr(coord: int): string = if coord == -1: result = "???" @@ -885,8 +890,7 @@ proc rawMessage*(msg: TMsgKind, arg: string) = proc resetAttributes* = if {optUseColors, optStdout} * gGlobalOptions == {optUseColors}: - terminal.resetAttributes() - stdout.flushFile() + terminal.resetAttributes(stderr) proc writeSurroundingSrc(info: TLineInfo) = const indent = " " @@ -1032,5 +1036,5 @@ proc listHints*() = ]) # enable colors by default on terminals -if terminal.isatty(stdout): +if terminal.isatty(stderr): incl(gGlobalOptions, optUseColors) |