NCurses: When mode line is too long, trim it rather hiding it

This commit is contained in:
Maxime Coste 2015-04-23 21:11:50 +01:00
parent e0f7a6f0be
commit 840e58e0b1
4 changed files with 19 additions and 8 deletions

View File

@ -169,11 +169,11 @@ CharCount DisplayLine::length() const
return len;
}
void DisplayLine::trim(CharCount first_char, CharCount char_count)
void DisplayLine::trim(CharCount first_char, CharCount char_count, bool only_buffer)
{
for (auto it = begin(); first_char > 0 and it != end(); )
{
if (not it->has_buffer_range())
if (only_buffer and not it->has_buffer_range())
{
++it;
continue;

View File

@ -114,7 +114,7 @@ public:
// remove first_char from the begining of the line, and make sure
// the line is less that char_count character
void trim(CharCount first_char, CharCount char_count);
void trim(CharCount first_char, CharCount char_count, bool only_buffer);
void optimize();
private:

View File

@ -388,14 +388,25 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer,
wmove(m_window, status_line_pos, 0);
wclrtoeol(m_window);
draw_line(status_line, 0);
CharCount status_len = mode_line.length();
// only draw mode_line if it does not overlap one status line
if (m_dimensions.column - status_line.length() > status_len + 1)
const auto mode_len = mode_line.length();
const auto remaining = m_dimensions.column - status_line.length();
if (mode_len < remaining)
{
CharCount col = m_dimensions.column - status_len;
CharCount col = m_dimensions.column - mode_len;
wmove(m_window, status_line_pos, (int)col);
draw_line(mode_line, col);
}
else if (remaining > 2)
{
DisplayLine trimmed_mode_line = mode_line;
trimmed_mode_line.trim(mode_len + 2 - remaining, remaining - 2, false);
trimmed_mode_line.insert(trimmed_mode_line.begin(), { "<" });
kak_assert(trimmed_mode_line.length() == remaining - 1);
CharCount col = m_dimensions.column - remaining + 1;
wmove(m_window, status_line_pos, (int)col);
draw_line(trimmed_mode_line, col);
}
const char* tsl = tigetstr((char*)"tsl");
const char* fsl = tigetstr((char*)"fsl");

View File

@ -83,7 +83,7 @@ void Window::update_display_buffer(const Context& context)
// cut the start of the line before m_position.column
for (auto& line : lines)
line.trim(m_position.column, m_dimensions.column);
line.trim(m_position.column, m_dimensions.column, true);
m_display_buffer.optimize();
m_timestamp = buffer().timestamp();