From 73bd9f7726bced532244c8a01facabe7e749adb2 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 4 May 2020 02:01:59 -0700 Subject: [PATCH] fix https://github.com/timotheecour/Nim/issues/152 `^[[0m` is inserted in stderr for `echo code | nim c -` --- compiler/msgs.nim | 5 ++++- compiler/options.nim | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 6fdd4931bb6a4..bd7cf4225b266 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -312,6 +312,8 @@ template styledMsgWriteln*(args: varargs[typed]) = else: if eStdErr in conf.m.errorOutputs: if optUseColors in conf.globalOptions: + # conf.options.ansiResetNeeded = true + conf.ansiResetNeeded = true callStyledWriteLineStderr(args) else: callIgnoringStyle(writeLine, stderr, args) @@ -443,7 +445,8 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, arg: string) = proc resetAttributes*(conf: ConfigRef) = if {optUseColors, optStdout} * conf.globalOptions == {optUseColors}: - terminal.resetAttributes(stderr) + if conf.ansiResetNeeded: + terminal.resetAttributes(stderr) proc addSourceLine(conf: ConfigRef; fileIdx: FileIndex, line: string) = conf.m.fileInfos[fileIdx.int32].lines.add line diff --git a/compiler/options.nim b/compiler/options.nim index 97cf435c55ad6..845f21445ea42 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -263,6 +263,7 @@ type projectPath*: AbsoluteDir # holds a path like /home/alice/projects/nim/compiler/ projectFull*: AbsoluteFile # projectPath/projectName projectIsStdin*: bool # whether we're compiling from stdin + ansiResetNeeded*: bool # whether resetAttributes is needed projectMainIdx*: FileIndex # the canonical path id of the main module command*: string # the main command (e.g. cc, check, scan, etc) commandArgs*: seq[string] # any arguments after the main command