Skip to content

Commit

Permalink
Merge pull request #1 from ncmreynolds/dev
Browse files Browse the repository at this point in the history
Fix single letter shortcuts
  • Loading branch information
ncmreynolds authored Apr 7, 2021
2 parents 4549a09 + 223fa43 commit 50ad95b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=retroTerm
version=0.1.0
version=0.1.1
author=Nick Reynolds,nick+retroTerm@arcanium.london
maintainer=Nick Reynolds,nick+retroTerm@arcanium.london
sentence=A library for creating user interfaces on an ANSI/VTxxx terminal with a microcontroller
Expand Down
64 changes: 49 additions & 15 deletions src/retroTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void retroTerm::_processInput()
_mouseStatus = _mouseStatus & 0xEF; //Gobble the mouse event
inputEventCaught = true; //Stop looking for more events
}
if(_widgets[widgetId].shortcut != noKeyPressed && _widgets[widgetId].shortcut == _lastKeypress) //Search for used keyboard shortcuts, which appear as 'clicks' of an object for simplicity. This gobbles up the keypress so the application doesn't see it
if(_widgets[widgetId].shortcut != noKeyPressed && _shortcutMatches(widgetId)) //Search for used keyboard shortcuts, which appear as 'clicks' of an object for simplicity. This gobbles up the keypress so the application doesn't see it
{
_clickWidget(widgetId); //Do per-widget-type click handling, only if clickable
_lastKeypress = noKeyPressed; //Gobble the keypress and stop looking for more shortcuts
Expand Down Expand Up @@ -290,6 +290,26 @@ void retroTerm::_processInput()
}
}

#if defined(ESP8266) || defined(ESP32)
bool ICACHE_FLASH_ATTR retroTerm::_shortcutMatches(const uint8_t widgetId)
#else
bool retroTerm::_shortcutMatches(const uint8_t widgetId)
#endif
{
if(_widgets[widgetId].shortcut == _lastKeypress)
{
return(true);
}
else if(_widgets[widgetId].shortcut > 31 && _lastKeypress > 31 && toupper(_widgets[widgetId].shortcut) == toupper(_lastKeypress))
{
return(true);
}
else
{
return(false);
}
}

#if defined(ESP8266) || defined(ESP32)
uint8_t ICACHE_FLASH_ATTR retroTerm::_typingXposition(const uint8_t widgetId)
#else
Expand Down Expand Up @@ -815,13 +835,20 @@ uint16_t ICACHE_FLASH_ATTR retroTerm::_shortcutLength(const uint8_t widgetIndex)
uint16_t retroTerm::_shortcutLength(const uint8_t widgetIndex)
#endif
{
#if defined(__AVR__)
return(strlen_P((const char *) pgm_read_word (&keyLabels[_widgets[widgetIndex].shortcut])));
#elif defined(ESP8266) || defined(ESP32)
return(strlen_P(keyLabels[_widgets[widgetIndex].shortcut]));
#else
return(strlen(keyLabels[_widgets[widgetIndex].shortcut]));
#endif
if(_widgets[widgetIndex].shortcut > 31) //It's a single character
{
return(1);
}
else
{
#if defined(__AVR__)
return(strlen_P((const char *) pgm_read_word (&keyLabels[_widgets[widgetIndex].shortcut])));
#elif defined(ESP8266) || defined(ESP32)
return(strlen_P(keyLabels[_widgets[widgetIndex].shortcut]));
#else
return(strlen(keyLabels[_widgets[widgetIndex].shortcut]));
#endif
}
}

#if defined(ESP8266) || defined(ESP32)
Expand Down Expand Up @@ -977,13 +1004,20 @@ void retroTerm::_printKeyboardShortcut(const uint8_t widgetIndex)
{
attributes(_widgets[widgetIndex].attributes); //Set the right attributes
_terminalStream->print(F("["));
#if defined(__AVR__)
_printProgStr((const char *) pgm_read_word (&keyLabels[_widgets[widgetIndex].shortcut]));
#elif defined(ESP8266) || defined(ESP32)
_terminalStream->print(keyLabels[_widgets[widgetIndex].shortcut]);
#else
_terminalStream->print(keyLabels[_widgets[widgetIndex].shortcut]);
#endif
if(_widgets[widgetIndex].shortcut > 31)
{
_terminalStream->print(char(_widgets[widgetIndex].shortcut));
}
else
{
#if defined(__AVR__)
_printProgStr((const char *) pgm_read_word (&keyLabels[_widgets[widgetIndex].shortcut]));
#elif defined(ESP8266) || defined(ESP32)
_terminalStream->print(keyLabels[_widgets[widgetIndex].shortcut]);
#else
_terminalStream->print(keyLabels[_widgets[widgetIndex].shortcut]);
#endif
}
_terminalStream->print(F("]"));
}

Expand Down
1 change: 1 addition & 0 deletions src/retroTerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ class retroTerm

void _displayKeyboardShortcut(uint8_t); //Show keyboard shortcut on a widget, doing all the lifting of centering etc.
void _printKeyboardShortcut(uint8_t); //Does the actual print. Uses appropriate method if shortcut is in a PROGMEM
bool _shortcutMatches(uint8_t); //Does case insensitive matching of keyboard shortcuts

void _displayLabel(uint8_t widgetId); //Show the label on a widget (will include shortcut if inline)
void _printLabel(uint8_t); //Does the actual print. Uses appropriate method if label is in a PROGMEM
Expand Down

0 comments on commit 50ad95b

Please sign in to comment.