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 std::string tmpstr = output; |
| 130 if (is_markdown && dec == DECORATION_YELLOW) { |
| 131 // https://code.google.com/p/gitiles/issues/detail?id=77 |
| 132 // Gitiles will replace "--" with an em dash in non-code text. |
| 133 // Figuring out all instances of this might be difficult, but we can |
| 134 // at least escape the instances where this shows up in a heading. |
| 135 base::ReplaceSubstringsAfterOffset(&tmpstr, 0, "--", "\\--"); |
| 136 } |
| 137 ::WriteFile(hstdout, tmpstr.c_str(), static_cast<DWORD>(tmpstr.size()), |
128 &written, nullptr); | 138 &written, nullptr); |
129 | 139 |
130 if (is_markdown) { | 140 if (is_markdown) { |
131 OutputMarkdownDec(dec); | 141 OutputMarkdownDec(dec); |
132 } else if (is_console) { | 142 } else if (is_console) { |
133 ::SetConsoleTextAttribute(hstdout, default_attributes); | 143 ::SetConsoleTextAttribute(hstdout, default_attributes); |
134 } | 144 } |
135 } | 145 } |
136 | 146 |
137 #else | 147 #else |
(...skipping 17 matching lines...) Expand all Loading... |
155 break; | 165 break; |
156 case DECORATION_BLUE: | 166 case DECORATION_BLUE: |
157 WriteToStdOut("\e[34m\e[1m"); | 167 WriteToStdOut("\e[34m\e[1m"); |
158 break; | 168 break; |
159 case DECORATION_YELLOW: | 169 case DECORATION_YELLOW: |
160 WriteToStdOut("\e[33m\e[1m"); | 170 WriteToStdOut("\e[33m\e[1m"); |
161 break; | 171 break; |
162 } | 172 } |
163 } | 173 } |
164 | 174 |
165 WriteToStdOut(output.data()); | 175 std::string tmpstr = output; |
| 176 if (is_markdown && dec == DECORATION_YELLOW) { |
| 177 // https://code.google.com/p/gitiles/issues/detail?id=77 |
| 178 // Gitiles will replace "--" with an em dash in non-code text. |
| 179 // Figuring out all instances of this might be difficult, but we can |
| 180 // at least escape the instances where this shows up in a heading. |
| 181 base::ReplaceSubstringsAfterOffset(&tmpstr, 0, "--", "\\--"); |
| 182 } |
| 183 WriteToStdOut(tmpstr.data()); |
166 | 184 |
167 if (is_markdown) { | 185 if (is_markdown) { |
168 OutputMarkdownDec(dec); | 186 OutputMarkdownDec(dec); |
169 } else if (is_console && dec != DECORATION_NONE) { | 187 } else if (is_console && dec != DECORATION_NONE) { |
170 WriteToStdOut("\e[0m"); | 188 WriteToStdOut("\e[0m"); |
171 } | 189 } |
172 } | 190 } |
173 | 191 |
174 #endif | 192 #endif |
175 | 193 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 274 } |
257 } | 275 } |
258 | 276 |
259 OutputString(line + "\n", dec); | 277 OutputString(line + "\n", dec); |
260 } | 278 } |
261 | 279 |
262 if (is_markdown && in_body) | 280 if (is_markdown && in_body) |
263 OutputString("\n```\n"); | 281 OutputString("\n```\n"); |
264 } | 282 } |
265 | 283 |
OLD | NEW |