Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: martine/ninja
base: ff877afa28
...
head fork: martine/ninja
compare: 649ad87148
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Showing with 29 additions and 13 deletions.
  1. +2 −13 src/build.cc
  2. +12 −0 src/util.cc
  3. +4 −0 src/util.h
  4. +11 −0 src/util_test.cc
View
15 src/build.cc
@@ -236,28 +236,17 @@ void BuildStatus::PrintStatus(Edge* edge) {
to_print = FormatProgressStatus(progress_status_format_) + to_print;
if (smart_terminal_ && !force_full_command) {
- const int kMargin = 3; // Space for "...".
#ifndef _WIN32
// Limit output to width of the terminal if provided so we don't cause
// line-wrapping.
winsize size;
if ((ioctl(0, TIOCGWINSZ, &size) == 0) && size.ws_col) {
- if (to_print.size() + kMargin > size.ws_col) {
- int elide_size = (size.ws_col - kMargin) / 2;
- to_print = to_print.substr(0, elide_size)
- + "..."
- + to_print.substr(to_print.size() - elide_size, elide_size);
- }
+ to_print = ElideMiddle(to_print, size.ws_col);
}
#else
// Don't use the full width or console will move to next line.
size_t width = static_cast<size_t>(csbi.dwSize.X) - 1;
- if (to_print.size() + kMargin > width) {
- int elide_size = (width - kMargin) / 2;
- to_print = to_print.substr(0, elide_size)
- + "..."
- + to_print.substr(to_print.size() - elide_size, elide_size);
- }
+ to_print = ElideMiddle(to_print, width);
#endif
}
View
12 src/util.cc
@@ -330,3 +330,15 @@ double GetLoadAverage() {
return loadavg[0];
}
#endif // _WIN32
+
+string ElideMiddle(const string& str, size_t width) {
+ const int kMargin = 3; // Space for "...".
+ string result = str;
+ if (result.size() + kMargin > width) {
+ int elide_size = (width - kMargin) / 2;
+ result = result.substr(0, elide_size)
+ + "..."
+ + result.substr(result.size() - elide_size, elide_size);
+ }
+ return result;
+}
View
4 src/util.h
@@ -70,6 +70,10 @@ int GetProcessorCount();
/// on error.
double GetLoadAverage();
+/// Elide the given string @a str with '...' in the middle if the length
+/// exceeds @a width.
+string ElideMiddle(const string& str, size_t width);
+
#ifdef _MSC_VER
#define snprintf _snprintf
#define fileno _fileno
View
11 src/util_test.cc
@@ -136,3 +136,14 @@ TEST(StripAnsiEscapeCodes, StripColors) {
EXPECT_EQ("affixmgr.cxx:286:15: warning: using the result... [-Wparentheses]",
stripped);
}
+
+TEST(ElideMiddle, NothingToElide) {
+ string input = "Nothing to elide in this short string.";
+ EXPECT_EQ(input, ElideMiddle(input, 80));
+}
+
+TEST(ElideMiddle, ElideInTheMiddle) {
+ string input = "01234567890123456789";
+ string elided = ElideMiddle(input, 10);
+ EXPECT_EQ("012...789", elided);
+}

No commit comments for this range

Something went wrong with that request. Please try again.