Skip to content

Commit

Permalink
actions: write_func_stream: Allow to strip comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfalcon committed Feb 25, 2017
1 parent b95ad40 commit 2c3b5b1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions scratchabit/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@


class TextSaveModel:
def __init__(self, f, ctrl=None):
def __init__(self, f, ctrl=None, comments=True):
self.f = f
self.ctrl = ctrl
self.cnt = 0
self.comments = comments
def add_line(self, addr, line):
line = ("%08x " % addr) + line.indent + line.render() + "\n"
txt = line.render()
if not self.comments and ";" in txt:
txt = txt.rsplit(";", 1)[0].rstrip()
if not txt.strip():
return
line = ("%08x " % addr) + line.indent + txt + "\n"
self.f.write(line)
if self.ctrl and self.cnt % 256 == 0:
self.ctrl.show_status("Writing: 0x%x" % addr)
self.cnt += 1


def write_func_stream(APP, func, stream, feedback_obj=None):
model = TextSaveModel(stream, feedback_obj)
def write_func_stream(APP, func, stream, feedback_obj=None, comments=True):
model = TextSaveModel(stream, feedback_obj, comments=comments)
for start, end in func.get_ranges():
while start < end:
start = engine.render_from(model, start, 1)
Expand Down

0 comments on commit 2c3b5b1

Please sign in to comment.