From f408cf7ed36857269a07d762e28dcfa2540d6d26 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 17 Feb 2016 15:32:05 +0200 Subject: [PATCH 1/5] 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, From 504f50417effe17bb2b51d897a22da459a8f1a84 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 17 Feb 2016 15:50:56 +0200 Subject: [PATCH 2/5] Declare the `BufferPadding` in the default themes --- colors/base16.kak | 1 + colors/default.kak | 1 + colors/github.kak | 1 + colors/lucius.kak | 1 + colors/reeder.kak | 1 + colors/solarized.kak | 1 + colors/zenburn.kak | 1 + 7 files changed, 7 insertions(+) diff --git a/colors/base16.kak b/colors/base16.kak index f382e714..9b0d122e 100644 --- a/colors/base16.kak +++ b/colors/base16.kak @@ -64,5 +64,6 @@ face StatusCursor ${black_lighterer},${cyan_light} face Prompt ${black_light},${cyan_light} face MatchingChar ${cyan_light},${black_light}+b + face BufferPadding ${cyan_light},${black_lighter} " } diff --git a/colors/default.kak b/colors/default.kak index b94472ee..925ba1b5 100644 --- a/colors/default.kak +++ b/colors/default.kak @@ -43,3 +43,4 @@ face StatusLineValue green,default face StatusCursor black,cyan face Prompt yellow,default face MatchingChar default,default+b +face BufferPadding blue,default diff --git a/colors/github.kak b/colors/github.kak index 7ce4ea28..736b19fa 100644 --- a/colors/github.kak +++ b/colors/github.kak @@ -43,3 +43,4 @@ face StatusCursor rgb:434343,rgb:CDCDFD face Prompt rgb:F8F8FF,rgb:4078C0 face MatchingChar rgb:F8F8FF,rgb:4078C0+b face Search default,default+u +face BufferPadding rgb:A0A0A0,rgb:F8F8FF diff --git a/colors/lucius.kak b/colors/lucius.kak index c8da0f11..1205d003 100644 --- a/colors/lucius.kak +++ b/colors/lucius.kak @@ -66,5 +66,6 @@ face StatusCursor default,${lucius_blue} face Prompt ${lucius_lighter_grey} face MatchingChar ${lucius_lighter_grey},${lucius_bright_green} + face BufferPadding ${lucius_green},${lucius_darker_grey} " } diff --git a/colors/reeder.kak b/colors/reeder.kak index 55ac9fbd..4acff1d2 100644 --- a/colors/reeder.kak +++ b/colors/reeder.kak @@ -64,5 +64,6 @@ face StatusCursor ${orange},${white_light} face Prompt ${black_light} face MatchingChar default+b + face BufferPadding ${grey_dark},${white} " } diff --git a/colors/solarized.kak b/colors/solarized.kak index efa060e1..a1e9b1db 100644 --- a/colors/solarized.kak +++ b/colors/solarized.kak @@ -64,5 +64,6 @@ face StatusCursor ${base00},${base3} face Prompt yellow face MatchingChar default+b + face BufferPadding ${base01},${base03} " } diff --git a/colors/zenburn.kak b/colors/zenburn.kak index 77953427..e4bd8d36 100644 --- a/colors/zenburn.kak +++ b/colors/zenburn.kak @@ -67,5 +67,6 @@ face StatusCursor ${zencursor} face Prompt yellow face MatchingChar default+b + face BufferPadding ${zenkeyword},${zenbackground} " } From 72cfa654480cfc5f25136cc2f3674ed432f8f9c5 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 17 Feb 2016 15:55:19 +0200 Subject: [PATCH 3/5] Document the `BufferPadding` face --- README.asciidoc | 1 + doc/manpages/faces.asciidoc | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.asciidoc b/README.asciidoc index 48f88cae..4c449876 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -920,6 +920,7 @@ There are some builtins faces used by internal Kakoune functionalities: * `Prompt`: face used prompt displayed on the status line * `MatchingChar`: face used by the show_matching highlighter * `Search`: face used to highlight search results + * `BufferPadding`: face applied on the characters that follow the last line of a buffer Advanced topics --------------- diff --git a/doc/manpages/faces.asciidoc b/doc/manpages/faces.asciidoc index 483200bc..f91f548a 100644 --- a/doc/manpages/faces.asciidoc +++ b/doc/manpages/faces.asciidoc @@ -94,3 +94,6 @@ areas of the user interface: *Search*:: face used to highlight search results + +*BufferPadding*:: + face applied on the characters that follow the last line of a buffer From ac08a1fa75480e423380ab204b4ddbc14fa5feb7 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 17 Feb 2016 16:02:05 +0200 Subject: [PATCH 4/5] Format the options' documentation properly --- src/main.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cc b/src/main.cc index 8ea034ab..319c8ff0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -252,8 +252,8 @@ void register_options() " ncurses_enable_mouse bool\n" " ncurses_wheel_up_button int\n" " ncurses_wheel_down_button int\n" - " ncurses_buffer_padding_str str\n" - " ncurses_buffer_padding_type fill|single|off\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); From e74878c299a53a1932fde492a8afc4a909b86ae0 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 17 Feb 2016 16:06:20 +0200 Subject: [PATCH 5/5] Cleanup/fix some code --- colors/reeder.kak | 2 +- colors/solarized.kak | 2 +- src/face_registry.cc | 2 +- src/ncurses_ui.cc | 3 +-- src/ncurses_ui.hh | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/colors/reeder.kak b/colors/reeder.kak index 4acff1d2..02095e59 100644 --- a/colors/reeder.kak +++ b/colors/reeder.kak @@ -64,6 +64,6 @@ face StatusCursor ${orange},${white_light} face Prompt ${black_light} face MatchingChar default+b - face BufferPadding ${grey_dark},${white} + face BufferPadding ${grey_dark},${white} " } diff --git a/colors/solarized.kak b/colors/solarized.kak index a1e9b1db..01404e8a 100644 --- a/colors/solarized.kak +++ b/colors/solarized.kak @@ -64,6 +64,6 @@ face StatusCursor ${base00},${base3} face Prompt yellow face MatchingChar default+b - face BufferPadding ${base01},${base03} + face BufferPadding ${base01},${base03} " } diff --git a/src/face_registry.cc b/src/face_registry.cc index 8eb68bb9..5af88e46 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -121,7 +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 } }, + { "BufferPadding", Face{ Color::Blue, Color::Default } }, } {} diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 735c02a1..1837dcf1 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -7,7 +7,6 @@ #include "keys.hh" #include "register_manager.hh" #include "utf8_iterator.hh" -#include "face_registry.hh" #include @@ -361,7 +360,7 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer, ++line_index; } - set_face(m_window, { Color::Blue, Color::Default }, padding_face); + set_face(m_window, padding_face, default_face); const DisplayLine padding_line = m_buffer_padding_str; const DisplayLine* padding_line_ptr = m_buffer_padding_type != BufferPaddingType::None ? diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index 9e5b458a..88dd77c1 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -124,7 +124,7 @@ private: int m_wheel_up_button = 4; int m_wheel_down_button = 5; - String m_buffer_padding_str = "~"; + String m_buffer_padding_str = "~"; BufferPaddingType m_buffer_padding_type = BufferPaddingType::None; bool m_set_title = true;