Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions linvam/profileexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
KEYS_SPLITTER, save_to_commands_file, is_push_to_listen, get_push_to_listen_hotkey, Command,
Config)

COMMAND_NAME_COMMA_SPLIT_REGGEX = r",(?![^\[]*\])"

# pylint: disable=too-many-locals
def _expand_optional_brackets(text):
"""
Expands optional words in square brackets to create all variations.
Expand All @@ -29,6 +31,7 @@ def _expand_optional_brackets(text):
Examples:
"power up [the ship]" -> ["power up the ship", "power up"]
"power up [the ship, the engines]" -> ["power up the ship", "power up the engines", "power up"]
# pylint: disable=line-too-long
"open [the, a] menu [now]" -> ["open the menu now", "open a menu now", "open the menu", "open a menu", "open menu now", "open menu"]

Args:
Expand Down Expand Up @@ -227,7 +230,7 @@ def set_profile(self, p_profile):
return
w_commands = self.m_profile['commands']
for w_command in w_commands:
parts = w_command['name'].strip().lower().split(',')
parts = re.split(COMMAND_NAME_COMMA_SPLIT_REGGEX, w_command['name'].strip().lower())
for part in parts:
# Expand optional brackets to create all variations
variations = _expand_optional_brackets(part.strip())
Expand Down Expand Up @@ -500,7 +503,7 @@ def _get_command_for_executing(self, cmd_name):
w_commands = self.m_profile['commands']
command = None
for w_command in w_commands:
parts = w_command['name'].split(',')
parts = re.split(COMMAND_NAME_COMMA_SPLIT_REGGEX, w_command['name'].strip().lower())
for part in parts:
# Expand optional brackets to match all variations
variations = _expand_optional_brackets(part.strip())
Expand Down