From a0cca31dc10f0faa4f5e611039874816fb276b59 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 20 Oct 2012 20:15:20 +0200 Subject: [PATCH] make UserInterface unaware of Window, only of DisplayBuffer --- src/commands.cc | 4 +++- src/context.hh | 10 +++++++++- src/ncurses.cc | 18 +++++++++++------- src/ncurses.hh | 5 ++++- src/user_interface.hh | 6 ++++-- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 92bfebc2a..45d4d37e4 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -657,12 +657,14 @@ public: bool has_key_left() const { return m_pos < m_keys.size(); } void print_status(const String& , CharCount) override {} - void draw_window(Window&) override {} + void draw(const DisplayBuffer&, const String&) override {} void menu_show(const memoryview&, const DisplayCoord&, MenuStyle) override {} void menu_select(int) override {} void menu_hide() override {} + DisplayCoord dimensions() override { return { 0, 0 }; } + private: const KeyList& m_keys; size_t m_pos; diff --git a/src/context.hh b/src/context.hh index 9c92bd83f..97c8e1c5f 100644 --- a/src/context.hh +++ b/src/context.hh @@ -94,7 +94,15 @@ struct Context void draw_ifn() const { if (has_ui() and has_window()) - ui().draw_window(window()); + { + DisplayCoord dimensions = ui().dimensions(); + if (dimensions == DisplayCoord{0,0}) + return; + window().set_dimensions(dimensions); + window().update_display_buffer();; + ui().draw(window().display_buffer(), window().status_line()); + } + } void print_status(const String& status) const diff --git a/src/ncurses.cc b/src/ncurses.cc index 57eabd4e1..0336090d3 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -1,6 +1,6 @@ #include "ncurses.hh" -#include "window.hh" +#include "display_buffer.hh" #include "register_manager.hh" #include "utf8_iterator.hh" @@ -113,18 +113,16 @@ void addutf8str(Utf8Iterator begin, Utf8Iterator end) addch(*begin++); } -void NCursesUI::draw_window(Window& window) +void NCursesUI::draw(const DisplayBuffer& display_buffer, + const String& status_line) { int max_x,max_y; getmaxyx(stdscr, max_y, max_x); max_y -= 1; int status_y = max_y; - window.set_dimensions(DisplayCoord(LineCount(max_y), max_x)); - window.update_display_buffer(); - int line_index = 0; - for (const DisplayLine& line : window.display_buffer().lines()) + for (const DisplayLine& line : display_buffer.lines()) { move(line_index, 0); clrtoeol(); @@ -169,7 +167,6 @@ void NCursesUI::draw_window(Window& window) } set_color(Color::Cyan, Color::Black); - String status_line = window.status_line(); static int last_status_length = 0; move(status_y, max_x - last_status_length); clrtoeol(); @@ -312,4 +309,11 @@ void NCursesUI::menu_hide() m_items.clear(); } +DisplayCoord NCursesUI::dimensions() +{ + int max_x,max_y; + getmaxyx(stdscr, max_y, max_x); + return {max_y - 1, max_x}; +} + } diff --git a/src/ncurses.hh b/src/ncurses.hh index fa8743bf2..060fc94fc 100644 --- a/src/ncurses.hh +++ b/src/ncurses.hh @@ -19,7 +19,8 @@ public: NCursesUI(const NCursesUI&) = delete; NCursesUI& operator=(const NCursesUI&) = delete; - void draw_window(Window& window) override; + void draw(const DisplayBuffer& display_buffer, + const String& status_line) override; void print_status(const String& status, CharCount cursor_pos) override; Key get_key() override; @@ -28,6 +29,8 @@ public: const DisplayCoord& anchor, MenuStyle style) override; void menu_select(int selected) override; void menu_hide() override; + + DisplayCoord dimensions() override; private: MENU* m_menu = nullptr; WINDOW* m_menu_win = nullptr; diff --git a/src/user_interface.hh b/src/user_interface.hh index 80b59c8a8..b1c116dc9 100644 --- a/src/user_interface.hh +++ b/src/user_interface.hh @@ -10,7 +10,7 @@ namespace Kakoune { class String; -class Window; +class DisplayBuffer; class DisplayCoord; enum class MenuStyle @@ -28,7 +28,9 @@ public: const DisplayCoord& anchor, MenuStyle style) = 0; virtual void menu_select(int selected) = 0; virtual void menu_hide() = 0; - virtual void draw_window(Window& window) = 0; + virtual void draw(const DisplayBuffer& display_buffer, + const String& status_line) = 0; + virtual DisplayCoord dimensions() = 0; virtual Key get_key() = 0; };