OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/standard_out.h" | 5 #include "tools/gn/standard_out.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_piece.h" | |
11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "tools/gn/switches.h" | 15 #include "tools/gn/switches.h" |
14 | 16 |
15 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
16 #include <windows.h> | 18 #include <windows.h> |
17 #else | 19 #else |
18 #include <stdio.h> | 20 #include <stdio.h> |
19 #include <unistd.h> | 21 #include <unistd.h> |
20 #endif | 22 #endif |
21 | 23 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 ::SetConsoleTextAttribute(hstdout, | 119 ::SetConsoleTextAttribute(hstdout, |
118 FOREGROUND_BLUE | FOREGROUND_INTENSITY); | 120 FOREGROUND_BLUE | FOREGROUND_INTENSITY); |
119 break; | 121 break; |
120 case DECORATION_YELLOW: | 122 case DECORATION_YELLOW: |
121 ::SetConsoleTextAttribute(hstdout, | 123 ::SetConsoleTextAttribute(hstdout, |
122 FOREGROUND_RED | FOREGROUND_GREEN); | 124 FOREGROUND_RED | FOREGROUND_GREEN); |
123 break; | 125 break; |
124 } | 126 } |
125 } | 127 } |
126 | 128 |
127 ::WriteFile(hstdout, output.c_str(), static_cast<DWORD>(output.size()), | 129 // https://code.google.com/p/gitiles/issues/detail?id=77 |
128 &written, nullptr); | 130 // Gitiles will replace "--" with an em dash in non-code text. |
131 // Figuring out all instances of this might be difficult, but | |
132 // we can at least escape the instances where this shows up in | |
133 // a heading. | |
134 if (is_markdown && dec==DECORATION_YELLOW) { | |
brettw
2015/09/04 18:04:29
Need spaces around ==
| |
135 std::string tmpstr = output; | |
brettw
2015/09/04 18:04:30
Why not just do
if (...) {
base::ReplaceSubs
Dirk Pranke
2015/09/05 01:53:42
output is a const, so we can't modify it.
I've u
| |
136 base::ReplaceSubstringsAfterOffset(&tmpstr, 0, | |
137 StringPiece("--"), | |
138 StringPiece("\\--")); | |
Dirk Pranke
2015/09/03 01:04:45
Is this the best/easiest way to do a "replace all"
brettw
2015/09/04 18:04:29
Sure, but you can remove the explicit StringPiece
| |
139 ::WriteFile(hstdout, tmpstr.c_str(), static_cast<DWORD>(tmpstr.size()), | |
140 &written, nullptr); | |
141 } else { | |
142 ::WriteFile(hstdout, output.c_str(), static_cast<DWORD>(output.size()), | |
143 &written, nullptr); | |
144 } | |
129 | 145 |
130 if (is_markdown) { | 146 if (is_markdown) { |
131 OutputMarkdownDec(dec); | 147 OutputMarkdownDec(dec); |
132 } else if (is_console) { | 148 } else if (is_console) { |
133 ::SetConsoleTextAttribute(hstdout, default_attributes); | 149 ::SetConsoleTextAttribute(hstdout, default_attributes); |
134 } | 150 } |
135 } | 151 } |
136 | 152 |
137 #else | 153 #else |
138 | 154 |
(...skipping 16 matching lines...) Expand all Loading... | |
155 break; | 171 break; |
156 case DECORATION_BLUE: | 172 case DECORATION_BLUE: |
157 WriteToStdOut("\e[34m\e[1m"); | 173 WriteToStdOut("\e[34m\e[1m"); |
158 break; | 174 break; |
159 case DECORATION_YELLOW: | 175 case DECORATION_YELLOW: |
160 WriteToStdOut("\e[33m\e[1m"); | 176 WriteToStdOut("\e[33m\e[1m"); |
161 break; | 177 break; |
162 } | 178 } |
163 } | 179 } |
164 | 180 |
165 WriteToStdOut(output.data()); | 181 if (is_markdown && dec==DECORATION_YELLOW) { |
brettw
2015/09/04 18:04:29
Ditto
| |
182 std::string tmpstr = output; | |
brettw
2015/09/04 18:04:29
Ditto
| |
183 | |
184 // https://code.google.com/p/gitiles/issues/detail?id=77 | |
185 // Gitiles will replace "--" with an em dash in non-code text. | |
186 // Figuring out all instances of this might be difficult, but | |
187 // we can at least escape the instances where this shows up in | |
188 // a heading. | |
189 base::ReplaceSubstringsAfterOffset(&tmpstr, 0, | |
190 base::StringPiece("--"), | |
191 base::StringPiece("\\--")); | |
192 WriteToStdOut(tmpstr.data()); | |
193 } else { | |
194 WriteToStdOut(output.data()); | |
195 } | |
166 | 196 |
167 if (is_markdown) { | 197 if (is_markdown) { |
168 OutputMarkdownDec(dec); | 198 OutputMarkdownDec(dec); |
169 } else if (is_console && dec != DECORATION_NONE) { | 199 } else if (is_console && dec != DECORATION_NONE) { |
170 WriteToStdOut("\e[0m"); | 200 WriteToStdOut("\e[0m"); |
171 } | 201 } |
172 } | 202 } |
173 | 203 |
174 #endif | 204 #endif |
175 | 205 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 } | 286 } |
257 } | 287 } |
258 | 288 |
259 OutputString(line + "\n", dec); | 289 OutputString(line + "\n", dec); |
260 } | 290 } |
261 | 291 |
262 if (is_markdown && in_body) | 292 if (is_markdown && in_body) |
263 OutputString("\n```\n"); | 293 OutputString("\n```\n"); |
264 } | 294 } |
265 | 295 |
OLD | NEW |