Allow users to chose how the buffers are padded

This commit is contained in:
Frank LENORMAND 2016-02-17 15:32:05 +02:00
parent 5de6963f74
commit f408cf7ed3
7 changed files with 49 additions and 11 deletions

View File

@ -166,7 +166,7 @@ void Client::redraw_ifn()
const bool needs_redraw = window.needs_redraw(context()); const bool needs_redraw = window.needs_redraw(context());
if (needs_redraw) 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(); DisplayLine mode_line = generate_mode_line();
if (needs_redraw or if (needs_redraw or

View File

@ -121,6 +121,7 @@ FaceRegistry::FaceRegistry()
{ "StatusCursor", Face{ Color::Black, Color::Cyan } }, { "StatusCursor", Face{ Color::Black, Color::Cyan } },
{ "Prompt", Face{ Color::Yellow, Color::Default } }, { "Prompt", Face{ Color::Yellow, Color::Default } },
{ "MatchingChar", Face{ Color::Default, Color::Default, Attribute::Bold } }, { "MatchingChar", Face{ Color::Default, Color::Default, Attribute::Bold } },
{ "BufferPadding", Face{ Color::Blue, Color::Default, Attribute::Bold } },
} }
{} {}

View File

@ -251,7 +251,9 @@ void register_options()
" ncurses_set_title bool\n" " ncurses_set_title bool\n"
" ncurses_enable_mouse bool\n" " ncurses_enable_mouse bool\n"
" ncurses_wheel_up_button int\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{}); UserInterface::Options{});
reg.declare_option("modelinefmt", "format string used to generate the modeline", reg.declare_option("modelinefmt", "format string used to generate the modeline",
"%val{bufname} %val{cursor_line}:%val{cursor_char_column} "_str); "%val{bufname} %val{cursor_line}:%val{cursor_char_column} "_str);
@ -292,7 +294,7 @@ std::unique_ptr<UserInterface> create_local_ui(bool dummy_ui)
void info_show(StringView, StringView, CharCoord, Face, InfoStyle) override {} void info_show(StringView, StringView, CharCoord, Face, InfoStyle) override {}
void info_hide() 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 {} void draw_status(const DisplayLine&, const DisplayLine&, const Face&) override {}
CharCoord dimensions() override { return {24,80}; } CharCoord dimensions() override { return {24,80}; }
bool is_key_available() override { return false; } bool is_key_available() override { return false; }

View File

@ -7,6 +7,7 @@
#include "keys.hh" #include "keys.hh"
#include "register_manager.hh" #include "register_manager.hh"
#include "utf8_iterator.hh" #include "utf8_iterator.hh"
#include "face_registry.hh"
#include <algorithm> #include <algorithm>
@ -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, 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))); wbkgdset(m_window, COLOR_PAIR(get_color_pair(default_face)));
@ -357,12 +361,18 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer,
++line_index; ++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)) while (line_index < m_dimensions.line + (m_status_on_top ? 1 : 0))
{ {
wmove(m_window, (int)line_index++, 0); wmove(m_window, (int)line_index++, 0);
wclrtoeol(m_window); 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; m_dirty = true;
@ -981,6 +991,20 @@ void NCursesUI::set_ui_options(const Options& options)
m_wheel_down_button = wheel_down_it != options.end() ? m_wheel_down_button = wheel_down_it != options.end() ?
str_to_int_ifp(wheel_down_it->value).value_or(5) : 5; 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;
}
} }
} }

View File

@ -13,6 +13,8 @@ namespace Kakoune
struct NCursesWin; struct NCursesWin;
enum BufferPaddingType { None, Single, Fill };
class NCursesUI : public UserInterface class NCursesUI : public UserInterface
{ {
public: public:
@ -23,7 +25,8 @@ public:
NCursesUI& operator=(const NCursesUI&) = delete; NCursesUI& operator=(const NCursesUI&) = delete;
void draw(const DisplayBuffer& display_buffer, 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, void draw_status(const DisplayLine& status_line,
const DisplayLine& mode_line, const DisplayLine& mode_line,
@ -121,6 +124,9 @@ private:
int m_wheel_up_button = 4; int m_wheel_up_button = 4;
int m_wheel_down_button = 5; 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_set_title = true;
bool m_dirty = false; bool m_dirty = false;

View File

@ -249,7 +249,8 @@ public:
void info_hide() override; void info_hide() override;
void draw(const DisplayBuffer& display_buffer, 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, void draw_status(const DisplayLine& status_line,
const DisplayLine& mode_line, const DisplayLine& mode_line,
@ -334,12 +335,14 @@ void RemoteUI::info_hide()
} }
void RemoteUI::draw(const DisplayBuffer& display_buffer, 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()); Message msg(m_socket_watcher.fd());
msg.write(RemoteUIMsg::Draw); msg.write(RemoteUIMsg::Draw);
msg.write(display_buffer); msg.write(display_buffer);
msg.write(default_face); msg.write(default_face);
msg.write(padding_face);
} }
void RemoteUI::draw_status(const DisplayLine& status_line, void RemoteUI::draw_status(const DisplayLine& status_line,
@ -504,7 +507,8 @@ void RemoteClient::process_next_message()
{ {
auto display_buffer = read<DisplayBuffer>(socket); auto display_buffer = read<DisplayBuffer>(socket);
auto default_face = read<Face>(socket); auto default_face = read<Face>(socket);
m_ui->draw(display_buffer, default_face); auto padding_face = read<Face>(socket);
m_ui->draw(display_buffer, default_face, padding_face);
break; break;
} }
case RemoteUIMsg::DrawStatus: case RemoteUIMsg::DrawStatus:

View File

@ -53,7 +53,8 @@ public:
virtual void info_hide() = 0; virtual void info_hide() = 0;
virtual void draw(const DisplayBuffer& display_buffer, 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, virtual void draw_status(const DisplayLine& status_line,
const DisplayLine& mode_line, const DisplayLine& mode_line,