From 585c8ba3cf486b706b5a1f31e2cf6a163d7485ea Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 16 May 2013 22:20:14 +0200 Subject: [PATCH] Show an info box with available option when waiting for a key Controled with the autoinfo option (disabled by default) --- src/normal.cc | 57 ++++++++++++++++++++++++++++++++++++++++--- src/option_manager.cc | 1 + 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index d8872469..1baed500 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -14,6 +14,7 @@ #include "shell_manager.hh" #include "string.hh" #include "window.hh" +#include "user_interface.hh" namespace Kakoune { @@ -31,6 +32,17 @@ void repeat_insert(Context& context) context.input_handler().repeat_last_insert(); } +bool show_auto_info_ifn(const String& info, const Context& context) +{ + if (not context.options()["autoinfo"].get() or not context.has_ui()) + return false; + ColorPair col{ Colors::Black, Colors::Yellow }; + DisplayCoord pos = context.window().dimensions(); + pos.column -= 1; + context.ui().info_show(info, pos , col, MenuStyle::Inline); + return true; +} + template void goto_commands(Context& context) { @@ -46,7 +58,22 @@ void goto_commands(Context& context) context.window().center_selection(); } else - context.input_handler().on_next_key([](const Key& key, Context& context) { + { + const bool hide = show_auto_info_ifn("╭────────┤goto├───────╮\n" + "│ g,k: buffer top │\n" + "│ l: line end │\n" + "│ h: line begin │\n" + "│ j: buffer bottom │\n" + "│ e: buffer end │\n" + "│ t: window top │\n" + "│ b: window bottom │\n" + "│ c: window center │\n" + "│ a: last buffer │\n" + "│ f: file │\n" + "╰─────────────────────╯\n", context); + context.input_handler().on_next_key([=](const Key& key, Context& context) { + if (hide) + context.ui().info_hide(); if (key.modifiers != Key::Modifiers::None) return; @@ -130,11 +157,21 @@ void goto_commands(Context& context) } } }); + } } void view_commands(Context& context) { - context.input_handler().on_next_key([](const Key& key, Context& context) { + const bool hide = show_auto_info_ifn("╭─────────┤view├─────────╮\n" + "│ v,c: center cursor │\n" + "│ t: cursor on top │\n" + "│ b: cursor on bottom │\n" + "│ j: scroll down │\n" + "│ k: scroll up │\n" + "╰────────────────────────╯\n", context); + context.input_handler().on_next_key([hide](const Key& key, Context& context) { + if (hide) + context.ui().info_hide(); if (key.modifiers != Key::Modifiers::None or not context.has_window()) return; @@ -504,8 +541,22 @@ void deindent(Context& context) template void select_object(Context& context) { + const bool hide = show_auto_info_ifn("╭──────┤select object├───────╮\n" + "│ b,(,): parenthesis block │\n" + "│ B,{,}: braces block │\n" + "│ [,]: brackets block │\n" + "│ <,>: angle block │\n" + "│ \": double quote string │\n" + "│ ': single quote string │\n" + "│ w: word │\n" + "│ W: WORD │\n" + "│ s: sentence │\n" + "│ p: paragraph │\n" + "╰────────────────────────────╯\n", context); context.input_handler().on_next_key( - [](const Key& key, Context& context) { + [=](const Key& key, Context& context) { + if (hide) + context.ui().info_hide(); typedef std::function Selector; static const std::unordered_map key_to_selector = { diff --git a/src/option_manager.cc b/src/option_manager.cc index 5dc330d7..80b78bbc 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -116,6 +116,7 @@ GlobalOptions::GlobalOptions() declare_option("shell", "bash"); declare_option("complete_prefix", true); declare_option("incsearch", true); + declare_option("autoinfo", false); declare_option("ignored_files", Regex{R"(^(\..*|.*\.(o|so|a))$)"}); declare_option("filetype", ""); declare_option>("completions", {});