Skip to content

Commit 89ffbab

Browse files
authored
allow printing QASM2 without color (#243)
this PR adds an option `no_color` so one does not need to create a rich Console manually.
1 parent 7f4b75a commit 89ffbab

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/bloqade/qasm2/parse/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@ def loadfile(file: str | pathlib.Path):
1919
return loads(f.read())
2020

2121

22-
def pprint(node: ast.Node, *, console: Console | None = None):
22+
def pprint(node: ast.Node, *, console: Console | None = None, no_color: bool = False):
2323
if console:
24-
return Printer(console).visit(node)
24+
printer = Printer(console)
2525
else:
26-
Printer().visit(node)
26+
printer = Printer()
27+
printer.console.no_color = no_color
28+
printer.visit(node)
2729

2830

29-
def spprint(node: ast.Node, *, console: Console | None = None):
31+
def spprint(node: ast.Node, *, console: Console | None = None, no_color: bool = False):
3032
if console:
3133
printer = Printer(console)
3234
else:
3335
printer = Printer()
3436

37+
printer.console.no_color = no_color
3538
with printer.string_io() as stream:
3639
printer.visit(node)
3740
return stream.getvalue()

0 commit comments

Comments
 (0)