diff --git a/README.asciidoc b/README.asciidoc index 1d797c0e..c4277eee 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -941,6 +941,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/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..02095e59 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..01404e8a 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} " } diff --git a/doc/json_ui.asciidoc b/doc/json_ui.asciidoc index 16f81468..98cdc049 100644 --- a/doc/json_ui.asciidoc +++ b/doc/json_ui.asciidoc @@ -21,7 +21,7 @@ Here are the data structures used: Here are the requests that can be written by the json ui on stdout: -* draw(Array lines, Face default_face) +* draw(Array lines, Face default_face, Face padding_face) * draw_status(Line status_line, Line mode_line, Face default_face) * menu_show(Array items, Coord anchor, Face fg, Face bg, diff --git a/doc/manpages/faces.asciidoc b/doc/manpages/faces.asciidoc index 2aea6fc7..91f4d6eb 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 diff --git a/src/client.cc b/src/client.cc index 06ee4260..3dc3ea07 100644 --- a/src/client.cc +++ b/src/client.cc @@ -190,7 +190,8 @@ void Client::redraw_ifn() if (m_ui_pending & Draw) { - m_ui->draw(window.update_display_buffer(context()), get_face("Default")); + m_ui->draw(window.update_display_buffer(context()), + get_face("Default"), get_face("BufferPadding")); if (not m_menu.items.empty() and m_menu.style == MenuStyle::Inline and m_menu.ui_anchor != window.display_position(m_menu.anchor)) diff --git a/src/face_registry.cc b/src/face_registry.cc index 7da57e9c..f5f415a2 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -120,6 +120,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 } }, } {} diff --git a/src/json_ui.cc b/src/json_ui.cc index aea412b1..05f0d38b 100644 --- a/src/json_ui.cc +++ b/src/json_ui.cc @@ -168,9 +168,9 @@ JsonUI::JsonUI() } void JsonUI::draw(const DisplayBuffer& display_buffer, - const Face& default_face) + const Face& default_face, const Face& padding_face) { - rpc_call("draw", display_buffer.lines(), default_face); + rpc_call("draw", display_buffer.lines(), default_face, padding_face); } void JsonUI::draw_status(const DisplayLine& status_line, diff --git a/src/json_ui.hh b/src/json_ui.hh index 3ebbafbb..e4d278fc 100644 --- a/src/json_ui.hh +++ b/src/json_ui.hh @@ -19,7 +19,8 @@ public: JsonUI& operator=(const JsonUI&) = delete; void draw(const DisplayBuffer& display_buffer, - const Face& default_face) override; + const Face& default_face, + const Face& buffer_padding) override; void draw_status(const DisplayLine& status_line, const DisplayLine& mode_line, diff --git a/src/main.cc b/src/main.cc index e14385ea..f7e2ea68 100644 --- a/src/main.cc +++ b/src/main.cc @@ -258,7 +258,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); @@ -308,7 +310,7 @@ std::unique_ptr make_ui(UIType ui_type) 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 da23807e..05ba0106 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -343,8 +343,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))); @@ -359,12 +362,18 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer, ++line_index; } - set_face(m_window, { Color::Blue, Color::Default }, default_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 ? + &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; @@ -982,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 870a3fc7..6f8d9fd9 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, @@ -126,6 +129,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 718d7f7d..d5a747cc 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, @@ -505,7 +508,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 e8a30a4b..26cf9097 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,