diff --git a/README.md b/README.md index 9f13ea5d..5b5c9a09 100644 --- a/README.md +++ b/README.md @@ -61,14 +61,14 @@ Interactive Commands: Ctrl-x send message Ctrl-y toggle show emojis KeyUp select message - Alt-$ external spell check - Alt-, decrease contact list width - Alt-. increase contact list width Alt-d delete/leave current chat Alt-e external editor compose + Alt-t external telephone call Alt-/ find in chat Alt-? find next in chat - Alt-t external telephone call + Alt-$ external spell check + Alt-, decrease contact list width + Alt-. increase contact list width Interactive Commands for Selected Message: diff --git a/lib/common/src/version.h b/lib/common/src/version.h index b6f24f6c..f98a1802 100644 --- a/lib/common/src/version.h +++ b/lib/common/src/version.h @@ -7,4 +7,4 @@ #pragma once -#define NCHAT_VERSION "4.90" +#define NCHAT_VERSION "4.91" diff --git a/src/main.cpp b/src/main.cpp index c22d32a3..9c45f79d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -613,13 +613,14 @@ void ShowHelp() " Ctrl-x send message\n" " Ctrl-y toggle show emojis\n" " KeyUp select message\n" - " Alt-$ external spell check\n" - " Alt-, decrease contact list width\n" - " Alt-. increase contact list width\n" + " Alt-d delete/leave current chat\n" " Alt-e external editor compose\n" + " Alt-t external telephone call\n" " Alt-/ find in chat\n" " Alt-? find next in chat\n" - " Alt-t external telephone call\n" + " Alt-$ external spell check\n" + " Alt-, decrease contact list width\n" + " Alt-. increase contact list width\n" "\n" "Interactive Commands for Selected Message:\n" " Ctrl-d delete selected message\n" diff --git a/src/nchat.1 b/src/nchat.1 index 31f96ee6..07ce8ec6 100644 --- a/src/nchat.1 +++ b/src/nchat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH NCHAT "1" "June 2024" "nchat v4.90" "User Commands" +.TH NCHAT "1" "June 2024" "nchat v4.91" "User Commands" .SH NAME nchat \- ncurses chat .SH SYNOPSIS @@ -85,26 +85,29 @@ toggle show emojis KeyUp select message .TP -Alt\-$ -external spell check -.TP -Alt\-, -decrease contact list width -.TP -Alt\-. -increase contact list width +Alt\-d +delete/leave current chat .TP Alt\-e external editor compose .TP +Alt\-t +external telephone call +.TP Alt\-/ find in chat .TP Alt\-? find next in chat .TP -Alt\-t -external telephone call +Alt\-$ +external spell check +.TP +Alt\-, +decrease contact list width +.TP +Alt\-. +increase contact list width .SS "Interactive Commands for Selected Message:" .TP Ctrl\-d diff --git a/src/uihelpview.cpp b/src/uihelpview.cpp index ca23b3db..21ae2e61 100644 --- a/src/uihelpview.cpp +++ b/src/uihelpview.cpp @@ -7,6 +7,8 @@ #include "uihelpview.h" +#include + #include "strutil.h" #include "uicolorconfig.h" #include "uikeyconfig.h" @@ -27,82 +29,105 @@ void UiHelpView::Draw() static std::wstring otherHelpItem = []() { std::vector helpItems; - AppendHelpItem(UiKeyConfig::GetKey("other_commands_help"), "OtherCmd", helpItems); + AppendHelpItem("other_commands_help", "OtherCmd", helpItems); return !helpItems.empty() ? L" | " + helpItems.at(0) : std::wstring(); }(); static std::vector listDialogHelpItems = []() { std::vector helpItems; - AppendHelpItem(UiKeyConfig::GetKey("ok"), "Select", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("cancel"), "Cancel", helpItems); - AppendHelpItem('a', "AddFiltr", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("backspace"), "DelFiltr", helpItems); + AppendHelpItem("ok", "Select", helpItems); + AppendHelpItem("cancel", "Cancel", helpItems); + AppendHelpItem("abc", "AddFiltr", helpItems); + AppendHelpItem("backspace", "DelFiltr", helpItems); return helpItems; }(); static std::vector messageDialogHelpItems = []() { std::vector helpItems; - AppendHelpItem(UiKeyConfig::GetKey("ok"), "OK", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("cancel"), "Cancel", helpItems); + AppendHelpItem("ok", "OK", helpItems); + AppendHelpItem("cancel", "Cancel", helpItems); return helpItems; }(); static std::vector editMessageHelpItems = []() { std::vector helpItems; - AppendHelpItem(UiKeyConfig::GetKey("send_msg"), "Save", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("cancel"), "Cancel", helpItems); + AppendHelpItem("send_msg", "Save", helpItems); + AppendHelpItem("cancel", "Cancel", helpItems); + return helpItems; + }(); + + static std::vector mainPreHelpItems = []() + { + std::vector helpItems; + AppendHelpItem("send_msg", "SendMsg", helpItems); + AppendHelpItem("next_chat", "NextChat", helpItems); + AppendHelpItem("unread_chat", "JumpUnrd", helpItems); + + AppendHelpItem("quit", "Quit", helpItems); + AppendHelpItem("select_emoji", "AddEmoji", helpItems); + AppendHelpItem("select_contact", "AddrBook", helpItems); + AppendHelpItem("transfer", "SendFile", helpItems); + return helpItems; }(); - static std::vector selectHelpItems = []() + static std::vector mainPostHelpItems = []() { std::vector helpItems; - AppendHelpItem(UiKeyConfig::GetKey("send_msg"), "ReplyMsg", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("next_chat"), "NextChat", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("unread_chat"), "JumpUnrd", helpItems); - - AppendHelpItem(UiKeyConfig::GetKey("quit"), "Quit", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("select_emoji"), "AddEmoji", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("select_contact"), "AddrBook", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("transfer"), "SendFile", helpItems); - - AppendHelpItem(UiKeyConfig::GetKey("up"), "PrevMsg", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("down"), "NextMsg", helpItems); - - AppendHelpItem(UiKeyConfig::GetKey("delete_msg"), "DelMsg", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("edit_msg"), "EditMsg", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("open"), "OpenFile", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("save"), "SaveFile", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("open_link"), "OpenLink", helpItems); - - AppendHelpItem(UiKeyConfig::GetKey("toggle_emoji"), "TgEmoji", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("toggle_list"), "TgList", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("toggle_top"), "TgTop", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("toggle_help"), "TgHelp", helpItems); + AppendHelpItem("ext_edit", "ExtEdit", helpItems); + AppendHelpItem("ext_call", "ExtCall", helpItems); + AppendHelpItem("find", "Find", helpItems); + AppendHelpItem("find_next", "FindNext", helpItems); + AppendHelpItem("spell", "ExtSpell", helpItems); + AppendHelpItem("decrease_list_width", "DecListW", helpItems); + AppendHelpItem("increase_list_width", "IncListW", helpItems); + + AppendHelpItem("cut", "Cut", helpItems); + AppendHelpItem("copy", "Copy", helpItems); + AppendHelpItem("paste", "Paste", helpItems); + + AppendHelpItem("toggle_emoji", "TgEmoji", helpItems); + AppendHelpItem("toggle_list", "TgList", helpItems); + AppendHelpItem("toggle_top", "TgTop", helpItems); + AppendHelpItem("toggle_help", "TgHelp", helpItems); + return helpItems; }(); - static std::vector defaultHelpItems = []() + static std::vector mainSelectHelpItems = []() { std::vector helpItems; - AppendHelpItem(UiKeyConfig::GetKey("send_msg"), "SendMsg", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("next_chat"), "NextChat", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("unread_chat"), "JumpUnrd", helpItems); + helpItems.insert(std::end(helpItems), std::begin(mainPreHelpItems), std::end(mainPreHelpItems)); + + AppendHelpItem("up", "PrevMsg", helpItems); + AppendHelpItem("down", "NextMsg", helpItems); + + AppendHelpItem("delete_msg", "DelMsg", helpItems); + AppendHelpItem("edit_msg", "EditMsg", helpItems); + AppendHelpItem("open", "OpenFile", helpItems); + AppendHelpItem("save", "SaveFile", helpItems); + AppendHelpItem("open_link", "OpenLink", helpItems); + + AppendHelpItem("jump_quoted", "JumpQuoted", helpItems); + AppendHelpItem("react", "AddReact", helpItems); + AppendHelpItem("open_msg", "ExtView", helpItems); + + helpItems.insert(std::end(helpItems), std::begin(mainPostHelpItems), std::end(mainPostHelpItems)); + return helpItems; + }(); - AppendHelpItem(UiKeyConfig::GetKey("quit"), "Quit", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("select_emoji"), "AddEmoji", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("select_contact"), "AddrBook", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("transfer"), "SendFile", helpItems); + static std::vector mainDefaultHelpItems = []() + { + std::vector helpItems; + helpItems.insert(std::end(helpItems), std::begin(mainPreHelpItems), std::end(mainPreHelpItems)); - AppendHelpItem(UiKeyConfig::GetKey("up"), "SelectMsg", helpItems); + AppendHelpItem("up", "SelectMsg", helpItems); + AppendHelpItem("delete_chat", "DelChat", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("toggle_emoji"), "TgEmoji", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("toggle_list"), "TgList", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("toggle_top"), "TgTop", helpItems); - AppendHelpItem(UiKeyConfig::GetKey("toggle_help"), "TgHelp", helpItems); + helpItems.insert(std::end(helpItems), std::begin(mainPostHelpItems), std::end(mainPostHelpItems)); return helpItems; }(); @@ -121,8 +146,8 @@ void UiHelpView::Draw() listDialogHelpViews = GetHelpViews(maxW, listDialogHelpItems, otherHelpItem); messageDialogHelpViews = GetHelpViews(maxW, messageDialogHelpItems, otherHelpItem); editMessageHelpViews = GetHelpViews(maxW, editMessageHelpItems, otherHelpItem); - selectHelpViews = GetHelpViews(maxW, selectHelpItems, otherHelpItem); - defaultHelpViews = GetHelpViews(maxW, defaultHelpItems, otherHelpItem); + selectHelpViews = GetHelpViews(maxW, mainSelectHelpItems, otherHelpItem); + defaultHelpViews = GetHelpViews(maxW, mainDefaultHelpItems, otherHelpItem); } static int colorPair = UiColorConfig::GetColorPair("help_color"); @@ -204,9 +229,9 @@ std::vector UiHelpView::GetHelpViews(const int p_MaxW, const std:: return helpViews; } -void UiHelpView::AppendHelpItem(const int p_Key, const std::string& p_Desc, std::vector& p_HelpItems) +void UiHelpView::AppendHelpItem(const std::string& p_Func, const std::string& p_Desc, std::vector& p_HelpItems) { - const std::string keyDisplay = GetKeyDisplay(p_Key); + const std::string keyDisplay = GetKeyDisplay(p_Func); if (!keyDisplay.empty()) { const std::string helpItem = keyDisplay + " " + p_Desc; @@ -214,57 +239,55 @@ void UiHelpView::AppendHelpItem(const int p_Key, const std::string& p_Desc, std: } } -std::string UiHelpView::GetKeyDisplay(int p_Key) +std::string UiHelpView::GetKeyDisplay(const std::string& p_Func) { - static int keyBackspace = UiKeyConfig::GetKeyCode("KEY_BACKSPACE"); - static int keyBackTab = UiKeyConfig::GetKeyCode("KEY_BTAB"); - static int keyDown = UiKeyConfig::GetKeyCode("KEY_DOWN"); - static int keyLeft = UiKeyConfig::GetKeyCode("KEY_LEFT"); - static int keyReturn = UiKeyConfig::GetKeyCode("KEY_RETURN"); - static int keyRight = UiKeyConfig::GetKeyCode("KEY_RIGHT"); - static int keyTab = UiKeyConfig::GetKeyCode("KEY_TAB"); - static int keyUp = UiKeyConfig::GetKeyCode("KEY_UP"); - - if (p_Key == keyReturn) + if (p_Func == "abc") return "abc"; + + const std::string keyName = UiKeyConfig::GetStr(p_Func); + if ((keyName.size() == 9) && (keyName >= "KEY_CTRLA") && (keyName <= "KEY_CTRLZ")) + { + return "^" + keyName.substr(8, 1); + } + else if (std::count(keyName.begin(), keyName.end(), '\\') == 2) + { + const std::string keyStr = StrUtil::StrFromOct(keyName); + if ((keyStr.size() == 2) && (keyStr.at(0) == '\33') && StrUtil::IsValidTextKey(keyStr.at(1))) + { + return "M-" + keyStr.substr(1); + } + } + else if (keyName == "KEY_RETURN") { return "\xe2\x8f\x8e"; } - else if (p_Key == keyTab) + else if (keyName == "KEY_TAB") { return "Tab"; } - else if (p_Key == keyBackTab) + else if (keyName == "KEY_BTAB") { return "STab"; } - else if (p_Key == keyUp) + else if (keyName == "KEY_UP") { return "\xe2\x86\x91"; } - else if (p_Key == keyDown) + else if (keyName == "KEY_DOWN") { return "\xe2\x86\x93"; } - else if (p_Key == keyLeft) + else if (keyName == "KEY_LEFT") { return "\xe2\x86\x90"; } - else if (p_Key == keyRight) + else if (keyName == "KEY_RIGHT") { return "\xe2\x86\x92"; } - else if (p_Key == keyBackspace) + else if (keyName == "KEY_BACKSPACE") { return "\xe2\x8c\xab"; } - else if (p_Key == 'a') - { - return "abc"; - } - else if ((p_Key >= 0x0) && (p_Key <= 0x1F)) - { - return "^" + std::string(1, (char)p_Key + 0x40); - } return ""; } diff --git a/src/uihelpview.h b/src/uihelpview.h index e264feb9..21b17948 100644 --- a/src/uihelpview.h +++ b/src/uihelpview.h @@ -1,6 +1,6 @@ // uihelpview.h // -// Copyright (c) 2019-2021 Kristofer Berggren +// Copyright (c) 2019-2024 Kristofer Berggren // All rights reserved. // // nchat is distributed under the MIT license, see LICENSE for details. @@ -22,6 +22,6 @@ class UiHelpView : public UiViewBase private: static std::vector GetHelpViews(const int p_MaxW, const std::vector& p_HelpItems, const std::wstring& p_OtherHelpItem); - static void AppendHelpItem(const int p_Key, const std::string& p_Desc, std::vector& p_HelpItems); - static std::string GetKeyDisplay(int p_Key); + static void AppendHelpItem(const std::string& p_Func, const std::string& p_Desc, std::vector& p_HelpItems); + static std::string GetKeyDisplay(const std::string& p_Func); }; diff --git a/src/uikeyconfig.cpp b/src/uikeyconfig.cpp index dd9319b8..38344876 100644 --- a/src/uikeyconfig.cpp +++ b/src/uikeyconfig.cpp @@ -264,6 +264,11 @@ void UiKeyConfig::Cleanup() m_Config.Save(); } +std::string UiKeyConfig::GetStr(const std::string& p_Param) +{ + return m_Config.Get(p_Param); +} + int UiKeyConfig::GetKey(const std::string& p_Param) { return GetKeyCode(m_Config.Get(p_Param)); diff --git a/src/uikeyconfig.h b/src/uikeyconfig.h index 487614ab..9ea50b9b 100644 --- a/src/uikeyconfig.h +++ b/src/uikeyconfig.h @@ -16,6 +16,7 @@ class UiKeyConfig public: static void Init(bool p_MapKeys); static void Cleanup(); + static std::string GetStr(const std::string& p_Param); static int GetKey(const std::string& p_Param); static int GetKeyCode(const std::string& p_KeyName); static std::string GetKeyName(int p_KeyCode);