File tree 1 file changed +23
-11
lines changed 1 file changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -1786,6 +1786,28 @@ async def mk_prompt(self, prompt_session:PromptSession):
1786
1786
return bufline
1787
1787
1788
1788
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
+
1789
1811
self .line = self .line [1 :].strip () # remove % and spaces
1790
1812
for tok in self .line .split (' ' ):
1791
1813
if not tok :
@@ -1795,17 +1817,7 @@ def handle_set_variable_commands(self):
1795
1817
var = tok [0 ].upper ()
1796
1818
if var in 'TGXNPSRCKFDR' : # global vars %
1797
1819
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 )
1809
1821
if not val or op == '.' :
1810
1822
val = op + val # append
1811
1823
# TODO: add numbers after dots like other ops
You can’t perform that action at this time.
0 commit comments