Skip to content

Commit fa52e5b

Browse files
author
Vance Palacio
committed
Move operator reading into its own function
1 parent 0627f10 commit fa52e5b

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

textbeat/player.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,28 @@ async def mk_prompt(self, prompt_session:PromptSession):
17861786
return bufline
17871787

17881788
def handle_set_variable_commands(self):
1789+
"""Function used to parse/handle variable setting commands. E.g: Set tempo, grid"""
1790+
1791+
# We define sub-functions since we don't want the entire module scope to have access to
1792+
# these. If it turns out that these are useful in a broader context, we can just rip em out
1793+
# at that point
1794+
def read_operands(cmd) -> tuple[str,str]:
1795+
"""Read the operator and value to use when modifying variables.
1796+
E.g: `+`, `-`, `=`
1797+
"""
1798+
op = cmd[1]
1799+
try:
1800+
val = cmd[2:]
1801+
except:
1802+
val = ''
1803+
# log("op val %s %s" % (op,val))
1804+
if op == ':': op = '='
1805+
if not op in '*/=-+':
1806+
# implicit =
1807+
val = str(op) + str(val)
1808+
op='='
1809+
return (val,op)
1810+
17891811
self.line = self.line[1:].strip() # remove % and spaces
17901812
for tok in self.line.split(' '):
17911813
if not tok:
@@ -1795,17 +1817,7 @@ def handle_set_variable_commands(self):
17951817
var = tok[0].upper()
17961818
if var in 'TGXNPSRCKFDR': # global vars %
17971819
cmd = tok.split(' ')[0]
1798-
op = cmd[1]
1799-
try:
1800-
val = cmd[2:]
1801-
except:
1802-
val = ''
1803-
# log("op val %s %s" % (op,val))
1804-
if op == ':': op = '='
1805-
if not op in '*/=-+':
1806-
# implicit =
1807-
val = str(op) + str(val)
1808-
op='='
1820+
(val,op) = read_operands(cmd)
18091821
if not val or op=='.':
18101822
val = op + val # append
18111823
# TODO: add numbers after dots like other ops

0 commit comments

Comments
 (0)