diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/format.cc | 15 | ||||
-rw-r--r-- | src/format.h | 6 | ||||
-rw-r--r-- | src/report.h | 17 |
3 files changed, 22 insertions, 16 deletions
diff --git a/src/format.cc b/src/format.cc index 4066cabd..6620e5a4 100644 --- a/src/format.cc +++ b/src/format.cc @@ -38,6 +38,9 @@ namespace ledger { +format_t::elision_style_t format_t::default_style = TRUNCATE_TRAILING; +bool format_t::default_style_changed = false; + void format_t::element_t::dump(std::ostream& out) const { out << "Element: "; @@ -386,22 +389,22 @@ string format_t::truncate(const unistring& ustr, std::size_t width, std::ostringstream buf; - elision_style_t style = TRUNCATE_TRAILING; - if (account_abbrev_length > 0) + elision_style_t style = default_style; + if (account_abbrev_length > 0 && ! default_style_changed) style = ABBREVIATE; switch (style) { case TRUNCATE_LEADING: // This method truncates at the beginning. - buf << ".." << ustr.extract(len - width, width); + buf << ".." << ustr.extract(len - (width - 2), width - 2); break; case TRUNCATE_MIDDLE: // This method truncates in the middle. - buf << ustr.extract(0, width / 2) + buf << ustr.extract(0, (width - 2) / 2) << ".." - << ustr.extract(len - (width / 2 + width % 2), - width / 2 + width % 2); + << ustr.extract(len - ((width - 2) / 2 + (width - 2) % 2), + (width - 2) / 2 + (width - 2) % 2); break; case ABBREVIATE: diff --git a/src/format.h b/src/format.h index 13dd0876..03ed28c7 100644 --- a/src/format.h +++ b/src/format.h @@ -107,12 +107,14 @@ class format_t : public noncopyable scoped_ptr<element_t> elements; public: - enum elision_style_t { + static enum elision_style_t { TRUNCATE_TRAILING, TRUNCATE_MIDDLE, TRUNCATE_LEADING, ABBREVIATE - }; + } default_style; + + static bool default_style_changed; private: static element_t * parse_elements(const string& fmt); diff --git a/src/report.h b/src/report.h index 45d4f11a..5a9fb8a5 100644 --- a/src/report.h +++ b/src/report.h @@ -52,6 +52,7 @@ #include "stream.h" #include "option.h" #include "commodity.h" +#include "format.h" namespace ledger { @@ -755,18 +756,18 @@ public: OPTION(report_t, total_data); - OPTION_(report_t, truncate_, DO() { -#if 0 + OPTION_(report_t, truncate_, DO_(args) { string style(args[1].to_string()); if (style == "leading") - format_t::elision_style = format_t::TRUNCATE_LEADING; + format_t::default_style = format_t::TRUNCATE_LEADING; else if (style == "middle") - format_t::elision_style = format_t::TRUNCATE_MIDDLE; + format_t::default_style = format_t::TRUNCATE_MIDDLE; else if (style == "trailing") - format_t::elision_style = format_t::TRUNCATE_TRAILING; - else if (style == "abbrev") - format_t::elision_style = format_t::ABBREVIATE; -#endif + format_t::default_style = format_t::TRUNCATE_TRAILING; + else + throw_(std::invalid_argument, + _("Unrecognized truncation style: '%1'") << style); + format_t::default_style_changed = true; }); OPTION_(report_t, unbudgeted, DO() { |