Skip to content

Commit

Permalink
show alt-key bindings in helpbar
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Jun 22, 2024
1 parent 6fd3675 commit c45de5b
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 98 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "4.90"
#define NCHAT_VERSION "4.91"
9 changes: 5 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 14 additions & 11 deletions src/nchat.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
173 changes: 98 additions & 75 deletions src/uihelpview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "uihelpview.h"

#include <algorithm>

#include "strutil.h"
#include "uicolorconfig.h"
#include "uikeyconfig.h"
Expand All @@ -27,82 +29,105 @@ void UiHelpView::Draw()
static std::wstring otherHelpItem = []()
{
std::vector<std::wstring> 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<std::wstring> listDialogHelpItems = []()
{
std::vector<std::wstring> 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<std::wstring> messageDialogHelpItems = []()
{
std::vector<std::wstring> 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<std::wstring> editMessageHelpItems = []()
{
std::vector<std::wstring> 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<std::wstring> mainPreHelpItems = []()
{
std::vector<std::wstring> 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<std::wstring> selectHelpItems = []()
static std::vector<std::wstring> mainPostHelpItems = []()
{
std::vector<std::wstring> 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<std::wstring> defaultHelpItems = []()
static std::vector<std::wstring> mainSelectHelpItems = []()
{
std::vector<std::wstring> 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<std::wstring> mainDefaultHelpItems = []()
{
std::vector<std::wstring> 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;
}();

Expand All @@ -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");
Expand Down Expand Up @@ -204,67 +229,65 @@ std::vector<std::wstring> UiHelpView::GetHelpViews(const int p_MaxW, const std::
return helpViews;
}

void UiHelpView::AppendHelpItem(const int p_Key, const std::string& p_Desc, std::vector<std::wstring>& p_HelpItems)
void UiHelpView::AppendHelpItem(const std::string& p_Func, const std::string& p_Desc, std::vector<std::wstring>& 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;
p_HelpItems.push_back(StrUtil::ToWString(helpItem));
}
}

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 "";
}
6 changes: 3 additions & 3 deletions src/uihelpview.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,6 +22,6 @@ class UiHelpView : public UiViewBase
private:
static std::vector<std::wstring> GetHelpViews(const int p_MaxW, const std::vector<std::wstring>& p_HelpItems,
const std::wstring& p_OtherHelpItem);
static void AppendHelpItem(const int p_Key, const std::string& p_Desc, std::vector<std::wstring>& p_HelpItems);
static std::string GetKeyDisplay(int p_Key);
static void AppendHelpItem(const std::string& p_Func, const std::string& p_Desc, std::vector<std::wstring>& p_HelpItems);
static std::string GetKeyDisplay(const std::string& p_Func);
};
5 changes: 5 additions & 0 deletions src/uikeyconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/uikeyconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c45de5b

Please sign in to comment.