diff --git a/src/filters.cc b/src/filters.cc index 7e534618..2f6450f5 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -70,7 +70,7 @@ void expand_tabulations(DisplayBuffer& display_buffer) atom_it = display_buffer.split(atom_it, it+1); BufferCoord pos = it.buffer().line_and_column_at(it); - + int column = 0; for (auto line_it = it.buffer().iterator_at({pos.line, 0}); line_it != it; ++line_it) @@ -90,4 +90,37 @@ void expand_tabulations(DisplayBuffer& display_buffer) } } +void show_line_numbers(DisplayBuffer& display_buffer) +{ + const Buffer& buffer = display_buffer.front().begin().buffer(); + BufferCoord coord = buffer.line_and_column_at(display_buffer.begin()->begin()); + + int last_line = buffer.line_and_column_at(display_buffer.back().end()-1).line; + + for (; coord.line <= last_line; ++coord.line) + { + BufferIterator line_start = buffer.iterator_at(coord); + DisplayBuffer::iterator atom_it = display_buffer.atom_containing(line_start); + if (atom_it != display_buffer.end()) + { + if (atom_it->begin() != line_start) + { + if (not atom_it->splitable()) + continue; + + atom_it = display_buffer.split(atom_it, line_start) + 1; + } + atom_it = display_buffer.insert( + atom_it, + DisplayAtom(atom_it->coord(), + atom_it->begin(), atom_it->begin(), + Color::Black, Color::White)); + + char buffer[6]; + snprintf(buffer, 6, "%3d ", coord.line); + display_buffer.replace_atom_content(atom_it, buffer); + } + } +} + } diff --git a/src/filters.hh b/src/filters.hh index 5d084eed..6ac37182 100644 --- a/src/filters.hh +++ b/src/filters.hh @@ -13,6 +13,7 @@ void colorize_regex(DisplayBuffer& display_buffer, void colorize_cplusplus(DisplayBuffer& display_buffer); void colorize_cplusplus(DisplayBuffer& display_buffer); void expand_tabulations(DisplayBuffer& display_buffer); +void show_line_numbers(DisplayBuffer& display_buffer); } diff --git a/src/window.cc b/src/window.cc index 50a5e908..39676066 100644 --- a/src/window.cc +++ b/src/window.cc @@ -114,6 +114,7 @@ Window::Window(Buffer& buffer) m_filters.push_back(colorize_cplusplus); m_filters.push_back(expand_tabulations); m_filters.push_back(HighlightSelections(*this)); + m_filters.push_back(show_line_numbers); } void Window::check_invariant() const