From ea7f76f7f27bd5fd461224b15c3eea9c7ce350f3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 3 Sep 2015 00:03:07 +0100 Subject: [PATCH] Change ncurses title logic, use hard coded \033]2;\007 sequence And add a ncurses_set_title ui option defaulting to true. --- README.asciidoc | 2 ++ src/ncurses_ui.cc | 23 ++++++++++++----------- src/ncurses_ui.hh | 2 ++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 02f8ba17..f2b2ec42 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -727,6 +727,8 @@ Some options are built in Kakoune, and can be used to control it's behaviour: modification is detected. * `ui_options`: colon separated list of key=value pairs that are forwarded to the user interface implementation. The NCurses UI support the following options: + - `ncurses_set_title`: if `yes` or `true`, the terminal emulator title will + be changed. - `ncurses_status_on_top`: if `yes`, or `true` the status line will be placed at the top of the terminal rather than at the bottom. - `ncurses_assistant`: specify the nice assistant you get in info boxes, can diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 49d523ed..19f5a3fd 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -413,16 +413,13 @@ void NCursesUI::draw_status(const DisplayLine& status_line, draw_line(trimmed_mode_line, col, default_face); } - const char* tsl = tigetstr((char*)"tsl"); - const char* fsl = tigetstr((char*)"fsl"); - if (tsl != 0 and (ptrdiff_t)tsl != -1 and - fsl != 0 and (ptrdiff_t)fsl != -1) + if (m_set_title) { - String title; + String title = "\033]2;"; for (auto& atom : mode_line) title += atom.content(); - title += " - Kakoune"; - printf("%s%s%s", tsl, title.c_str(), fsl); + title += " - Kakoune\007"; + write(1, title.data(), (int)title.length()); } m_dirty = true; @@ -930,10 +927,14 @@ void NCursesUI::set_ui_options(const Options& options) { auto it = options.find("ncurses_status_on_top"); - if (it == options.end()) - m_status_on_top = false; - else - m_status_on_top = it->second == "yes" or it->second == "true"; + m_status_on_top = it != options.end() and + (it->second == "yes" or it->second == "true"); + } + + { + auto it = options.find("ncurses_set_title"); + m_set_title = it == options.end() or + (it->second == "yes" or it->second == "true"); } { diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index 9669ecf5..f68e6a8d 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -83,6 +83,8 @@ private: int m_wheel_down_button = 2; int m_wheel_up_button = 4; + bool m_set_title = true; + bool m_dirty = false; };