From f408cf7ed36857269a07d762e28dcfa2540d6d26 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 17 Feb 2016 15:32:05 +0200 Subject: [PATCH] Allow users to chose how the buffers are padded --- src/client.cc | 2 +- src/face_registry.cc | 1 + src/main.cc | 6 ++++-- src/ncurses_ui.cc | 30 +++++++++++++++++++++++++++--- src/ncurses_ui.hh | 8 +++++++- src/remote.cc | 10 +++++++--- src/user_interface.hh | 3 ++- 7 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/client.cc b/src/client.cc index 3a4f44ed..eeea3396 100644 --- a/src/client.cc +++ b/src/client.cc @@ -166,7 +166,7 @@ void Client::redraw_ifn() const bool needs_redraw = window.needs_redraw(context()); if (needs_redraw) - ui.draw(window.update_display_buffer(context()), get_face("Default")); + ui.draw(window.update_display_buffer(context()), get_face("Default"), get_face("BufferPadding")); DisplayLine mode_line = generate_mode_line(); if (needs_redraw or diff --git a/src/face_registry.cc b/src/face_registry.cc index 3a5ac6e1..8eb68bb9 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -121,6 +121,7 @@ FaceRegistry::FaceRegistry() { "StatusCursor", Face{ Color::Black, Color::Cyan } }, { "Prompt", Face{ Color::Yellow, Color::Default } }, { "MatchingChar", Face{ Color::Default, Color::Default, Attribute::Bold } }, + { "BufferPadding", Face{ Color::Blue, Color::Default, Attribute::Bold } }, } {} diff --git a/src/main.cc b/src/main.cc index 1640c504..8ea034ab 100644 --- a/src/main.cc +++ b/src/main.cc @@ -251,7 +251,9 @@ void register_options() " ncurses_set_title bool\n" " ncurses_enable_mouse bool\n" " ncurses_wheel_up_button int\n" - " ncurses_wheel_down_button int\n", + " ncurses_wheel_down_button int\n" + " ncurses_buffer_padding_str str\n" + " ncurses_buffer_padding_type fill|single|off\n", UserInterface::Options{}); reg.declare_option("modelinefmt", "format string used to generate the modeline", "%val{bufname} %val{cursor_line}:%val{cursor_char_column} "_str); @@ -292,7 +294,7 @@ std::unique_ptr create_local_ui(bool dummy_ui) void info_show(StringView, StringView, CharCoord, Face, InfoStyle) override {} void info_hide() override {} - void draw(const DisplayBuffer&, const Face&) override {} + void draw(const DisplayBuffer&, const Face&, const Face&) override {} void draw_status(const DisplayLine&, const DisplayLine&, const Face&) override {} CharCoord dimensions() override { return {24,80}; } bool is_key_available() override { return false; } diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index a4f5b50c..735c02a1 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -7,6 +7,7 @@ #include "keys.hh" #include "register_manager.hh" #include "utf8_iterator.hh" +#include "face_registry.hh" #include @@ -341,8 +342,11 @@ void NCursesUI::draw_line(NCursesWin* window, const DisplayLine& line, } } +static const DisplayLine empty_line = String(" "); + void NCursesUI::draw(const DisplayBuffer& display_buffer, - const Face& default_face) + const Face& default_face, + const Face& padding_face) { wbkgdset(m_window, COLOR_PAIR(get_color_pair(default_face))); @@ -357,12 +361,18 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer, ++line_index; } - set_face(m_window, { Color::Blue, Color::Default }, default_face); + set_face(m_window, { Color::Blue, Color::Default }, padding_face); + + const DisplayLine padding_line = m_buffer_padding_str; + const DisplayLine* padding_line_ptr = m_buffer_padding_type != BufferPaddingType::None ? + &padding_line : &empty_line; while (line_index < m_dimensions.line + (m_status_on_top ? 1 : 0)) { wmove(m_window, (int)line_index++, 0); wclrtoeol(m_window); - waddch(m_window, '~'); + draw_line(m_window, *padding_line_ptr, 0, m_dimensions.column, padding_face); + if (m_buffer_padding_type == BufferPaddingType::Single) + padding_line_ptr = &empty_line; } m_dirty = true; @@ -981,6 +991,20 @@ void NCursesUI::set_ui_options(const Options& options) m_wheel_down_button = wheel_down_it != options.end() ? str_to_int_ifp(wheel_down_it->value).value_or(5) : 5; } + + { + auto padding_str_it = options.find("ncurses_buffer_padding_str"); + m_buffer_padding_str = padding_str_it == options.end() or !padding_str_it->value.length() ? + "~" : padding_str_it->value; + + auto padding_type_it = options.find("ncurses_buffer_padding_type"); + if (padding_type_it == options.end() or padding_type_it->value == "fill") + m_buffer_padding_type = BufferPaddingType::Fill; + else if (padding_type_it->value == "single") + m_buffer_padding_type = BufferPaddingType::Single; + else + m_buffer_padding_type = BufferPaddingType::None; + } } } diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index 59cf8846..9e5b458a 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -13,6 +13,8 @@ namespace Kakoune struct NCursesWin; +enum BufferPaddingType { None, Single, Fill }; + class NCursesUI : public UserInterface { public: @@ -23,7 +25,8 @@ public: NCursesUI& operator=(const NCursesUI&) = delete; void draw(const DisplayBuffer& display_buffer, - const Face& default_face) override; + const Face& default_face, + const Face& padding_face) override; void draw_status(const DisplayLine& status_line, const DisplayLine& mode_line, @@ -121,6 +124,9 @@ private: int m_wheel_up_button = 4; int m_wheel_down_button = 5; + String m_buffer_padding_str = "~"; + BufferPaddingType m_buffer_padding_type = BufferPaddingType::None; + bool m_set_title = true; bool m_dirty = false; diff --git a/src/remote.cc b/src/remote.cc index e2756ef1..c99d5611 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -249,7 +249,8 @@ public: void info_hide() override; void draw(const DisplayBuffer& display_buffer, - const Face& default_face) override; + const Face& default_face, + const Face& padding_face) override; void draw_status(const DisplayLine& status_line, const DisplayLine& mode_line, @@ -334,12 +335,14 @@ void RemoteUI::info_hide() } void RemoteUI::draw(const DisplayBuffer& display_buffer, - const Face& default_face) + const Face& default_face, + const Face& padding_face) { Message msg(m_socket_watcher.fd()); msg.write(RemoteUIMsg::Draw); msg.write(display_buffer); msg.write(default_face); + msg.write(padding_face); } void RemoteUI::draw_status(const DisplayLine& status_line, @@ -504,7 +507,8 @@ void RemoteClient::process_next_message() { auto display_buffer = read(socket); auto default_face = read(socket); - m_ui->draw(display_buffer, default_face); + auto padding_face = read(socket); + m_ui->draw(display_buffer, default_face, padding_face); break; } case RemoteUIMsg::DrawStatus: diff --git a/src/user_interface.hh b/src/user_interface.hh index 67553922..b3f45677 100644 --- a/src/user_interface.hh +++ b/src/user_interface.hh @@ -53,7 +53,8 @@ public: virtual void info_hide() = 0; virtual void draw(const DisplayBuffer& display_buffer, - const Face& default_face) = 0; + const Face& default_face, + const Face& padding_face) = 0; virtual void draw_status(const DisplayLine& status_line, const DisplayLine& mode_line,