Skip to content

Commit 26c8761

Browse files
author
Vance Palacio
committed
Factor out the prompt generating function
1 parent e9c697b commit 26c8761

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

textbeat/player.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,40 +1908,44 @@ async def try_stop_on_index_error(self, prompt_session:PromptSession) -> LoopRes
19081908
ch.release_all()
19091909

19101910
if self.shell:
1911-
# self.shell PROMPT
1912-
# log(orr(self.tracks[0].scale,self.scale).mode_name(orr(self.tracks[0].mode,self.mode)))
1913-
# cur_oct = self.tracks[0].octave
1914-
# cline = FG.GREEN + 'txbt> '+FG.BLUE+ '('+str(int(self.tempo))+'bpm x'+str(int(self.grid))+' '+\
1915-
# note_name(self.tracks[0].transpose) + ' ' +\
1916-
# orr(self.tracks[0].scale,self.scale).mode_name(orr(self.tracks[0].mode,self.mode,-1))+\
1917-
# ')> '
1918-
modename = orr(self.tracks[0].scale,self.scale).mode_name(orr(self.tracks[0].mode,self.mode,-1))
1919-
1920-
keynote = note_name(self.transpose + self.tracks[0].transpose)
1921-
keynote = keynote if keynote!='C' else ''
1922-
parts = [
1923-
str(int(self.tempo))+'bpm', # tempo
1924-
'x'+str(int(self.grid)), # subdiv
1925-
keynote,
1926-
('' if modename=='ionian' else modename)
1927-
]
1928-
cline = 'txbt> ('+ \
1929-
' '.join(filter(lambda x: x, parts))+ \
1930-
')> '
1931-
# if bufline.endswith('.txbt'):
1932-
# play file?
1933-
# bufline = raw_input(cline)
1934-
bufline = await prompt_session.prompt_async(cline)
1935-
bufline = list(filter(None, bufline.split(' ')))
1936-
bufline = list(map(lambda b: b.replace(';',' '), bufline))
1911+
self.buf += await self.mk_prompt(prompt_session)
19371912
# elif self.remote:
19381913
# pass # not yet implemented
19391914
else:
1940-
assert False
1941-
1942-
self.buf += bufline
1943-
1915+
assert False
19441916
return LoopResult.CONTINUE
19451917

19461918
else:
19471919
return LoopResult.BREAK
1920+
return LoopResult.PROCEED
1921+
1922+
async def mk_prompt(self, prompt_session:PromptSession):
1923+
"""Creates a new prompt for the current line"""
1924+
# self.shell PROMPT
1925+
# log(orr(self.tracks[0].scale,self.scale).mode_name(orr(self.tracks[0].mode,self.mode)))
1926+
# cur_oct = self.tracks[0].octave
1927+
# cline = FG.GREEN + 'txbt> '+FG.BLUE+ '('+str(int(self.tempo))+'bpm x'+str(int(self.grid))+' '+\
1928+
# note_name(self.tracks[0].transpose) + ' ' +\
1929+
# orr(self.tracks[0].scale,self.scale).mode_name(orr(self.tracks[0].mode,self.mode,-1))+\
1930+
# ')> '
1931+
modename = orr(self.tracks[0].scale,self.scale).mode_name(orr(self.tracks[0].mode,self.mode,-1))
1932+
1933+
keynote = note_name(self.transpose + self.tracks[0].transpose)
1934+
keynote = keynote if keynote!='C' else ''
1935+
parts = [
1936+
str(int(self.tempo))+'bpm', # tempo
1937+
'x'+str(int(self.grid)), # subdiv
1938+
keynote,
1939+
('' if modename=='ionian' else modename)
1940+
]
1941+
cline = 'txbt> ('+ \
1942+
' '.join(filter(lambda x: x, parts))+ \
1943+
')> '
1944+
# if bufline.endswith('.txbt'):
1945+
# play file?
1946+
# bufline = raw_input(cline)
1947+
bufline = await prompt_session.prompt_async(cline)
1948+
bufline = list(filter(None, bufline.split(' ')))
1949+
bufline = list(map(lambda b: b.replace(';',' '), bufline))
1950+
1951+
return bufline

0 commit comments

Comments
 (0)