Skip to content

Commit c7afb24

Browse files
add options and label formatting option
1 parent c2d1cfa commit c7afb24

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

schemascii/__main__.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,51 @@ def cli_main():
99
prog="schemascii",
1010
description="Render ASCII-art schematics into SVG.")
1111
ap.add_argument("-V", "--version",
12-
type="version",
13-
version=__version__)
12+
action="version",
13+
version="%(prog)s " + __version__)
1414
ap.add_argument("in_file",
1515
help="File to process.")
1616
ap.add_argument("-o", "--out",
1717
default=None,
1818
dest="out_file",
1919
help="Output SVG file. (default input file plus .svg)")
20+
ap.add_argument("--padding",
21+
help="Amount of padding to add on the edges.",
22+
type=int,
23+
default=10)
24+
ap.add_argument("--scale",
25+
help="Scale at which to enlarge the entire diagram by.",
26+
type=int,
27+
default=15)
28+
ap.add_argument("--stroke_width",
29+
help="Width of the lines",
30+
type=int,
31+
default=2)
32+
ap.add_argument("--stroke",
33+
help="Color of the lines.",
34+
default="black")
35+
ap.add_argument("--label",
36+
help="Component label style "
37+
"(L=include label, V=include value, VL=both)",
38+
choices="L V VL".split(),
39+
default="VL")
2040
args = ap.parse_args()
2141
if args.out_file is None:
2242
args.out_file = args.in_file + ".svg"
43+
text = None
44+
if args.in_file == "-":
45+
text = sys.stdin.read()
46+
args.in_file = "<stdin>"
2347
try:
24-
result_svg = render(args.in_file)
48+
result_svg = render(args.in_file, text, **vars(args))
2549
except Error as err:
2650
print(repr(err), file=sys.stderr)
2751
sys.exit(1)
28-
with open(args.out_file, "w", encoding="utf-8") as out:
29-
out.write(result_svg)
52+
if args.out_file == "-":
53+
print(result_svg)
54+
else:
55+
with open(args.out_file, "w", encoding="utf-8") as out:
56+
out.write(result_svg)
3057

3158

3259
if __name__ == '__main__':

schemascii/components_render.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def integrated_circuit(
200200
bom_data: BOMData | None,
201201
**options):
202202
"Draw an IC"
203+
label_style = options.get("label", "VL")
203204
scale = options.get("scale", 1)
204205
sz = (box.p2 - box.p1) * scale
205206
mid = (box.p2 + box.p1) * scale / 2
@@ -217,9 +218,10 @@ def integrated_circuit(
217218
term.pt + rect(1, SIDE_TO_ANGLE_MAP[term.side])
218219
)], **options)
219220
out += XML.text(
220-
XML.tspan(f"{box.type}{box.id}", class_="cmp-id"),
221-
" " * bool(bom_data.data),
222-
XML.tspan(bom_data.data, class_="part-num"),
221+
(XML.tspan(f"{box.type}{box.id}", class_="cmp-id")
222+
* bool("L" in label_style)),
223+
" " * (bool(bom_data.data) and "L" in label_style),
224+
XML.tspan(bom_data.data, class_="part-num") * bool("V" in label_style),
223225
x=mid.real,
224226
y=mid.imag,
225227
text__anchor="middle",

schemascii/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def id_text(
148148
point: complex | None = None,
149149
**options):
150150
"Format the component ID and value around the point"
151+
label_style = options.get("label", "VL")
151152
if point is None:
152153
point = sum(t.pt for t in terminals) / len(terminals)
153154
data = ""
@@ -165,9 +166,10 @@ def id_text(
165166
classy = "cmp-value"
166167
data = XML.tspan(text, class_=classy)
167168
return XML.text(
168-
XML.tspan(f"{box.type}{box.id}", class_="cmp-id"),
169-
" " * bool(data),
170-
data,
169+
(XML.tspan(f"{box.type}{box.id}", class_="cmp-id")
170+
* bool("L" in label_style)),
171+
" " * (bool(data) and "L" in label_style),
172+
data * bool("V" in label_style),
171173
x=point.real,
172174
y=point.imag,
173175
text__anchor="start" if (

test_data/test_resistors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| | |
1313
| *--------------*-----C3+---*
1414
| 2 |
15-
| .~~~. *----CV1 CV1:5p
15+
| .~~~. *-CV1-* CV1:5p
1616
*--1:U1 :3-----*
1717
.~~~.
1818
U1:7805

test_data/test_resistors.txt.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)