Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Correct modifyOtherKeys=2 behaviour for certain Shift-modified keys
Browse files Browse the repository at this point in the history
Closes #94
  • Loading branch information
tomscii committed Oct 29, 2022
1 parent 846c013 commit 5331995
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions src/vterm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -735,20 +735,32 @@ namespace zutty
int
Vterm::writePty (uint8_t ch, VtModifier modifiers, bool userInput)
{
using VM = VtModifier;

auto uch = (unsigned char*)&ch;
logT << "pty write (mod=" << (int)modifiers << "): "
<< dumpBuffer (uch, uch + 1);

if ((modifyOtherKeys == 2 && modifiers != VtModifier::none) ||
(modifyOtherKeys == 1 &&
(modifiers & VtModifier::control) != VtModifier::none &&
const auto& mod2_encode =
[&] (uint8_t ch)
{
const char* exempt = "!#$%&*()-+=?.,:;<>'\"";
auto x = const_cast <char*> (exempt);

while (*x)
if (ch == *x++)
return (modifiers & VM::control_alt) != VM::none;

return modifiers != VM::none;
};

if ((modifyOtherKeys == 2 && mod2_encode (ch)) ||
(modifyOtherKeys == 1 && (modifiers & VM::control) != VM::none &&
ch > ' '))
{
if (ch < ' ' &&
(modifiers & VtModifier::control) != VtModifier::none)
if (ch < ' ' && (modifiers & VM::control) != VM::none)
{
const char* ctrlmap =
((modifiers & VtModifier::shift) != VtModifier::none)
const char* ctrlmap = ((modifiers & VM::shift) != VM::none)
? "@ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}^/"
: " abcdefghijklmnopqrstuvwxyz[\\]^/";
ch = ctrlmap [ch];
Expand Down Expand Up @@ -778,7 +790,7 @@ namespace zutty

return writePty (wbuf, pos, userInput);
}
else if ((modifiers & VtModifier::alt) != VtModifier::none)
else if ((modifiers & VM::alt) != VM::none)
{
if (altSendsEscape)
{
Expand Down
2 changes: 1 addition & 1 deletion test/keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ function SPECIAL_KEYS {
IN "alt-tab \A\[Tab] \D2"
IN "alt-x \Ax \D2"

SNAP keys_13 ceb5fe868904bc8f716254a0ce6f3807
SNAP keys_13 0a9dd49f6b5754fda882458c3a5be730

IN "\Cd\Cd\D3"
}
Expand Down

0 comments on commit 5331995

Please sign in to comment.