monotone-commits-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-commits-diffs] net.venge.monotone.colored-diff: 69d8be9ae7a29


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone.colored-diff: 69d8be9ae7a295bde86e3ae74f622ace78a2c0fd
Date: Sun, 10 Apr 2011 13:05:04 +0200 (CEST)

revision:            69d8be9ae7a295bde86e3ae74f622ace78a2c0fd
date:                2011-04-10T11:04:15
author:              Richard Hopkins <address@hidden>
branch:              net.venge.monotone.colored-diff
changelog:
Laying foundation to support colorization on Windows

The problem is that Windows does not support ANSI codes so we must rely on
the API call side effects.

This probably means all output should go through colorizer regardless, as
text to be formatted needs to output AFTER the side effect, but also in the
correct place regarding other output.

eg.
Current code looks something like this

cout << "Non colored text" << '\n';
cout << color.colorize(add, "new_file.txt") << '\n';
cout << "More non colored text" << '\n';

Here, the colorizer needs a reference to cout so it can buffer the
"new_file.txt" to the output at the correct time. In this case everything
should work because it's all going through to cout.

However, other code looks like this

oss << "Non colored text" << '\n';
oss << color.colorize(add, "new_file.txt") << '\n';
oss << "More non colored text" << '\n';
..
cout << oss.str();

Here, even if the colorizer has access to cout so "new_file.txt" can be
output at the correct time to be formatted, everything would be out of
order due to the other output being buffered into oss, and then output to
cout.

If everything, colored + non-colored went through the colorizer we could
solve both problems - but this means a tree wide change to all output, so
it would look something like this.

color.write("Non colored text\n");
color.colorize(add, "new_file.txt\n");
color.write("More non colored text"\n');

manifest:
format_version "1"

new_manifest [bd722d02df375226939e1f268f52fa993f268060]

old_revision [8c57a6ba773f45b33a0c2308c93de34d80e820e4]

patch "src/colorizer.cc"
 from [770dbe7f2c330c9f08c413985497a052b38a2f31]
   to [70f28456415ac886e8449d8ffc5596bfa267b2ef]

patch "src/colorizer.hh"
 from [edcd644f94e2d14dd47e72aadaee6ce9562b7053]
   to [8daedb1c6b54672327e57b5f39dd4c69631969b1]
============================================================
--- src/colorizer.cc	770dbe7f2c330c9f08c413985497a052b38a2f31
+++ src/colorizer.cc	70f28456415ac886e8449d8ffc5596bfa267b2ef
@@ -164,7 +164,7 @@ colorizer::colorize(string const & in, p
   if (colormap.find(p) == colormap.end())
     return in;
 
-  return get_format(p) + in + get_format(reset);
+  return change_format(p) + in + change_format(reset);
 }
 
 string
@@ -175,6 +175,29 @@ colorizer::get_format(purpose const p) c
   return format.get<0>() + format.get<1>() + format.get<2>();
 }
 
+string
+colorizer::change_format(purpose const p) const
+{
+#ifdef WIN32
+  I(false); // FIXME: Needs implementing
+  // We will have to rely on Win32 API calls for the side effect of
+  // changing output, but to keep callers happy regardless of platform we
+  // will return an empty string so they can have code like
+  //
+  // change_format(add) + "new_file.txt" + change_format(reset)
+  //
+  // on Windows, this will become "new_file.txt" as the API calls will have
+  // changed the format for us.
+  //
+  // on everything else, this will become
+  // "<ANSI_CODE>new_file.txt<ANSI_CODE>" and the terminal will then display
+  // the properly formatted "new_file.txt"
+  return "";
+#else
+  return get_format(p);
+#endif
+}
+
 // Local Variables:
 // mode: C++
 // fill-column: 76
============================================================
--- src/colorizer.hh	edcd644f94e2d14dd47e72aadaee6ce9562b7053
+++ src/colorizer.hh	8daedb1c6b54672327e57b5f39dd4c69631969b1
@@ -52,6 +52,7 @@ private:
   std::string style_to_code(std::string const style) const;
 
   std::string get_format(purpose const p) const;
+  std::string change_format(purpose const p) const;
 
   std::string purpose_to_name(purpose const p) const;
 };

reply via email to

[Prev in Thread] Current Thread [Next in Thread]