diff options
author | John Wiegley <johnw@newartisans.com> | 2012-02-26 02:18:22 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-02-26 02:18:22 -0600 |
commit | 4cf95497f9afaead3d9d308dabe8e8b26949502f (patch) | |
tree | 99ea35c41def6930cfe4fe56711752e5366a175f /src | |
parent | 40ab81308025e9655074da37671c444b4257f867 (diff) | |
download | fork-ledger-4cf95497f9afaead3d9d308dabe8e8b26949502f.tar.gz fork-ledger-4cf95497f9afaead3d9d308dabe8e8b26949502f.tar.bz2 fork-ledger-4cf95497f9afaead3d9d308dabe8e8b26949502f.zip |
Keep notes on their own line if parsed that way
Diffstat (limited to 'src')
-rw-r--r-- | src/item.h | 10 | ||||
-rw-r--r-- | src/print.cc | 15 | ||||
-rw-r--r-- | src/textual.cc | 2 |
3 files changed, 18 insertions, 9 deletions
@@ -100,9 +100,10 @@ private: class item_t : public supports_flags<uint_least16_t>, public scope_t { public: -#define ITEM_NORMAL 0x00 // no flags at all, a basic posting -#define ITEM_GENERATED 0x01 // posting was not found in a journal -#define ITEM_TEMP 0x02 // posting is a managed temporary +#define ITEM_NORMAL 0x00 // no flags at all, a basic posting +#define ITEM_GENERATED 0x01 // posting was not found in a journal +#define ITEM_TEMP 0x02 // posting is a managed temporary +#define ITEM_NOTE_ON_NEXT_LINE 0x04 // did we see a note on the next line? enum state_t { UNCLEARED = 0, CLEARED, PENDING }; @@ -117,7 +118,8 @@ public: optional<string_map> metadata; item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none) - : supports_flags<uint_least16_t>(_flags), _state(UNCLEARED), note(_note) + : supports_flags<uint_least16_t>(_flags), _state(UNCLEARED), + note(_note) { TRACE_CTOR(item_t, "flags_t, const string&"); } diff --git a/src/print.cc b/src/print.cc index 215ab30b..6725a336 100644 --- a/src/print.cc +++ b/src/print.cc @@ -43,12 +43,15 @@ namespace ledger { namespace { void print_note(std::ostream& out, const string& note, + const bool note_on_next_line, const std::size_t columns, const std::size_t prior_width) { - // The 4 is for four leading spaces at the beginning of the posting, and - // the 3 is for two spaces and a semi-colon before the note. - if (columns > 0 && note.length() > columns - (prior_width + 3)) + // The 3 is for two spaces and a semi-colon before the note. + if (note_on_next_line || + (columns > 0 && + (columns <= prior_width + 3 || + note.length() > columns - (prior_width + 3)))) out << "\n ;"; else out << " ;"; @@ -103,7 +106,8 @@ namespace { static_cast<std::size_t>(report.HANDLER(columns_).value.to_long()) : 80); if (xact.note) - print_note(out, *xact.note, columns, unistring(leader).length()); + print_note(out, *xact.note, xact.has_flags(ITEM_NOTE_ON_NEXT_LINE), + columns, unistring(leader).length()); out << '\n'; if (xact.metadata) { @@ -226,7 +230,8 @@ namespace { } if (post->note) - print_note(out, *post->note, columns, 4 + account_width); + print_note(out, *post->note, post->has_flags(ITEM_NOTE_ON_NEXT_LINE), + columns, 4 + account_width); out << '\n'; } } diff --git a/src/textual.cc b/src/textual.cc index c7c49e2a..ddbd9943 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -577,6 +577,7 @@ void instance_t::automated_xact_directive(char * line) // This is a trailing note, and possibly a metadata info tag item->append_note(p + 1, context.scope, true); + item->add_flags(ITEM_NOTE_ON_NEXT_LINE); item->pos->end_pos = curr_pos; item->pos->end_line++; @@ -1529,6 +1530,7 @@ xact_t * instance_t::parse_xact(char * line, if (*p == ';') { // This is a trailing note, and possibly a metadata info tag item->append_note(p + 1, context.scope, true); + item->add_flags(ITEM_NOTE_ON_NEXT_LINE); item->pos->end_pos = curr_pos; item->pos->end_line++; } |