[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone.colored-diff: 168fa25fb8271
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone.colored-diff: 168fa25fb8271090aa8e94fb398dc03999b51a04 |
Date: |
Sun, 16 Jan 2011 17:06:25 GMT |
revision: 168fa25fb8271090aa8e94fb398dc03999b51a04
date: 2011-01-16T17:04:22
author: Richard Hopkins
branch: net.venge.monotone.colored-diff
changelog:
Colorizer now handles fore+back color along with styling
get_output_color now handles returning a triple containing
the foreground color, background color and style to use. An
empty string means Monotone will take care of it for you.
NOTE: The color_table explictly specifies fg, bg and style
with "" as it wouldn't work with nil's - I think extract_str
is the cause.
manifest:
format_version "1"
new_manifest [8ff4227aaf5bd2fc4cccd612a81291b76075425c]
old_revision [6932e29a4cbeefeb1e14d10d0ac0e543af34f7a7]
patch "colorizer.cc"
from [e95e4da35986b1b33fef3de093d319d7701ff3a7]
to [96964884a83e4d7d638c146821a554d033f396eb]
patch "colorizer.hh"
from [43cf62c869f21fa9696c17905f204509c70addf3]
to [eb3d0e3dad8d447e270e0c6264bf1a4ea139013f]
patch "lua_hooks.cc"
from [fe99f629e609c034a1a6f428232b92ce6b99ec22]
to [cd982157b1248b75f37edda84723e8944c70c5bf]
patch "lua_hooks.hh"
from [50c8b64894595ad317c1c9cda176563445431b6c]
to [a7ab69e459aa1f8450ac10704f0c22a595cc69e8]
patch "std_hooks.lua"
from [063f7f36a7e3e5454eb9a14118083ccc37f3d361]
to [7669463d1a401dc786dbf65fc99d1a4853cf4a4f]
============================================================
--- lua_hooks.cc fe99f629e609c034a1a6f428232b92ce6b99ec22
+++ lua_hooks.cc cd982157b1248b75f37edda84723e8944c70c5bf
@@ -770,14 +770,17 @@ bool
}
bool
-lua_hooks::hook_get_output_color(string const purpose, string & color)
+lua_hooks::hook_get_output_color(string const purpose, string & fg,
+ string & bg, string & style)
{
Lua ll = Lua(st);
return ll.func("get_output_color")
.push_str(purpose)
- .call(1, 1)
- .extract_str(color)
+ .call(1, 3)
+ .extract_str(style).pop()
+ .extract_str(bg).pop()
+ .extract_str(fg)
.ok();
}
============================================================
--- lua_hooks.hh 50c8b64894595ad317c1c9cda176563445431b6c
+++ lua_hooks.hh a7ab69e459aa1f8450ac10704f0c22a595cc69e8
@@ -169,7 +169,8 @@ public:
bool hook_get_man_page_formatter_command(string & command);
- bool hook_get_output_color(string const purpose, string & color);
+ bool hook_get_output_color(string const purpose, string & fg,
+ string & bg, string & style);
// notification hooks
bool hook_note_commit(revision_id const & new_id,
============================================================
--- std_hooks.lua 063f7f36a7e3e5454eb9a14118083ccc37f3d361
+++ std_hooks.lua 7669463d1a401dc786dbf65fc99d1a4853cf4a4f
@@ -1533,35 +1533,40 @@ function get_output_color(purpose)
end
function get_output_color(purpose)
- -- returns a friendly color name which will be converted by monotone
- -- into the relevant ASCII escape code.
- -- valid return values are
- -- "" for monotone to use the default output
- -- black, white, red, green, blue, magenta, yellow, cyan, bold, reset
+ -- Returns a triple containing the fore color, background color and
+ -- style to use for formatting the output.
+ -- The fore color and background color can be any of the following
+ -- red, green, blue, yellow, cyan, magenta, black, white
+ -- Alternatively, they can be the empty string and Monotone will
+ -- decide.
+ -- Valid values for style are
+ -- none, bold, italic, underline
+ -- Alternatively, it can be the empty string and Monotone will
+ -- decide.
+ local default_color = { fg = "", bg = "", style = "" }
local color_table =
{
- normal = "",
- reset = "reset",
+ normal = default_color,
- add = "green",
- change = "blue",
- comment = "yellow",
- encloser = "magenta",
- log_revision = "bold",
- remove = "red",
- rename = "yellow",
- rev_header = "bold",
- separator = "bold",
- set = "cyan",
- unset = "magenta"
+ add = { fg = "green", bg = "", style = "" },
+ change = { fg = "blue", bg = "", style = "" },
+ comment = { fg = "yellow", bg = "", style = "" },
+ encloser = { fg = "magenta", bg = "", style = "" },
+ log_revision = { fg = "", bg = "", style = "bold" },
+ remove = { fg = "red", bg = "", style = "" },
+ rename = { fg = "yellow", bg = "", style = "" },
+ rev_header = { fg = "", bg = "", style = "bold" },
+ separator = { fg = "", bg = "", style = "bold" },
+ set = { fg = "cyan", bg = "", style = "" },
+ unset = { fg = "magenta", bg = "", style = "" }
}
local chosen_color = color_table[purpose]
if chosen_color == nil then
- return ""
+ return default_color
else
- return chosen_color
+ return chosen_color.fg, chosen_color.bg, chosen_color.style
end
end
============================================================
--- colorizer.cc e95e4da35986b1b33fef3de093d319d7701ff3a7
+++ colorizer.cc 96964884a83e4d7d638c146821a554d033f396eb
@@ -53,43 +53,86 @@ string colorizer::purpose_to_name(colori
}
}
-std::pair<colorizer::purpose, string> colorizer::map_output_color(
+std::pair<colorizer::purpose, boost::tuple<string, string, string> > colorizer::map_output_color(
purpose const p)
{
- string color;
+ string fg, bg, style;
string purpose_name = purpose_to_name(p);
- lua.hook_get_output_color(purpose_name, color);
+ if (p == reset)
+ {
+ // the user doesn't need to know about reset - it's an implementation
+ // detail for us to handle
+ fg = bg = style = "";
+ }
+ else
+ {
+ lua.hook_get_output_color(purpose_name, fg, bg, style);
+ }
- return std::make_pair(p, color_to_code(color));
+ return std::make_pair(p, boost::make_tuple(fg_to_code(fg),
+ bg_to_code(bg),
+ style_to_code(style)));
}
-string colorizer::color_to_code(string const color) const
+string colorizer::fg_to_code(string const color) const
{
- if (color == "red")
+ if (color == "black")
+ return "\033[30m";
+ else if (color == "red")
return "\033[31m";
else if (color == "green")
return "\033[32m";
+ else if (color == "yellow")
+ return "\033[33m";
else if (color == "blue")
return "\033[34m";
else if (color == "magenta")
return "\033[35m";
- else if (color == "yellow")
- return "\033[33m";
else if (color == "cyan")
return "\033[36m";
- else if (color == "reset")
- return "\033[m";
- else if (color == "bold")
- return "\033[1m";
- else if (color == "black")
- return "\033[30m";
else if (color == "white")
return "\033[37m";
else
- return "\033[37m"; // no color specified - so use default (white)
+ return "\033[39m"; // default
}
+string colorizer::bg_to_code(string const color) const
+{
+ if (color == "black")
+ return "\033[40m";
+ else if (color == "red")
+ return "\033[41m";
+ else if (color == "green")
+ return "\033[42m";
+ else if (color == "yellow")
+ return "\033[43m";
+ else if (color == "blue")
+ return "\033[44m";
+ else if (color == "magenta")
+ return "\033[45m";
+ else if (color == "cyan")
+ return "\033[46m";
+ else if (color == "white")
+ return "\033[47m";
+ else
+ return "\033[49m"; // default
+}
+
+string colorizer::style_to_code(string const style) const
+{
+ if (style == "none")
+ return "\033[22m\033[23m\033[24m";
+ else if (style == "bold")
+ return "\033[1m";
+ else if (style == "italic")
+ return "\033[3m";
+ else if (style == "underline")
+ return "\033[4m";
+ else
+ return "\033[22m\033[23m\033[24m"; // all off
+}
+
colorizer::colorizer(bool enable, lua_hooks & lh)
: lua(lh)
{
@@ -120,9 +163,18 @@ colorizer::colorize(string const & in, p
{
if (colormap.find(p) == colormap.end())
return in;
- return colormap.find(p)->second + in + colormap.find(reset)->second;
+
+ return get_format(p) + in + get_format(reset);
}
+string
+colorizer::get_format(purpose const p) const
+{
+ boost::tuple<string, string, string> format = colormap.find(p)->second;
+
+ return format.get<0>() + format.get<1>() + format.get<2>();
+}
+
// Local Variables:
// mode: C++
// fill-column: 76
============================================================
--- colorizer.hh 43cf62c869f21fa9696c17905f204509c70addf3
+++ colorizer.hh eb3d0e3dad8d447e270e0c6264bf1a4ea139013f
@@ -13,6 +13,7 @@
#include "lua_hooks.hh"
#include "vocab.hh"
#include <map>
+#include <boost/tuple/tuple.hpp>
struct colorizer {
@@ -38,13 +39,19 @@ private:
colorize(std::string const & in, purpose p = normal) const;
private:
- std::map<purpose, std::string> colormap;
+ std::map<purpose, boost::tuple<std::string, std::string, std::string> >
+ colormap;
lua_hooks & lua;
-
- std::pair<purpose, std::string>
+
+ std::pair<purpose, boost::tuple<std::string, std::string, std::string> >
map_output_color(purpose const p);
- std::string color_to_code(std::string const color) const;
+ std::string fg_to_code(std::string const color) const;
+ std::string bg_to_code(std::string const color) const;
+ std::string style_to_code(std::string const style) const;
+
+ std::string get_format(purpose const p) const;
+
std::string purpose_to_name(purpose const p) const;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone.colored-diff: 168fa25fb8271090aa8e94fb398dc03999b51a04,
code <=