From 6411193f105f41c34f9419ff3b303a010794f75e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 25 Jan 2012 20:22:33 +0000 Subject: [PATCH] SelectionHighlighter: reverse color of the last char of each selection the terminal cursor is now longer shown --- src/highlighters.cc | 21 +++++++++++++++++---- src/main.cc | 5 ++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index ed1d4abeb..b837ca883 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -206,6 +206,7 @@ public: auto atom_it = display_buffer.begin(); auto sel_it = selections.begin(); + // underline each selections while (atom_it != display_buffer.end() and sel_it != selections.end()) { @@ -253,10 +254,22 @@ public: assert(false); } - boost::regex ex("\n"); - for (auto& sel : selections) - colorize_regex_range(display_buffer, sel.first, sel.second, - ex, Color::Default, Color::Yellow); + // invert selection last char + for (auto& sel : m_window.selections()) + { + const BufferIterator& last = sel.last(); + + DisplayBuffer::iterator atom_it = display_buffer.atom_containing(last); + if (atom_it == display_buffer.end()) + continue; + + if (atom_it->begin() < last) + atom_it = ++display_buffer.split(atom_it, last); + if (atom_it->end() > last + 1) + atom_it = display_buffer.split(atom_it, last + 1); + + atom_it->attribute() |= Attributes::Reverse; + } } diff --git a/src/main.cc b/src/main.cc index 57aa4492a..7291dda79 100644 --- a/src/main.cc +++ b/src/main.cc @@ -195,7 +195,7 @@ void init_ncurses() nonl(); intrflush(stdscr, false); keypad(stdscr, true); - curs_set(2); + curs_set(0); start_color(); ESCDELAY=25; } @@ -209,6 +209,9 @@ struct prompt_aborted {}; std::string ncurses_prompt(const std::string& text, Completer completer = complete_nothing) { + curs_set(2); + auto restore_cursor = on_scope_end([]() { curs_set(0); }); + int max_x, max_y; getmaxyx(stdscr, max_y, max_x); move(max_y-1, 0);