python-barcode icon indicating copy to clipboard operation
python-barcode copied to clipboard

Feature request - terminal output

Open Mikael-Lovqvist opened this issue 6 months ago • 3 comments
trafficstars

Sometimes you want to generate and scan a code in a terminal. Here is a thing I tried out, maybe it could become a feature in this library.

I made a quick example here but I am not sure I understand the proper way of subclassing BaseWriter in this project.

It will output something like the image below. Only tested on dark terminal with code128.

Image

I could only fit 2 sub modules per character because I could only find box drawing characters that could span all combinations for half width. If there is a right 3/4 bar one could double the density but I have not looked for one.

Mikael-Lovqvist avatar May 12 '25 22:05 Mikael-Lovqvist

This looks pretty convenient.

Currently subclasses of BaseWriter are in barcode/writer.py, I think it's feasible to include an AsciiWriter there. The target can be a file-like, where one can pass simply stdout or an actual file.

WhyNotHugo avatar May 17 '25 19:05 WhyNotHugo

If you want to take a shot at it, happy to review a PR for it.

WhyNotHugo avatar May 17 '25 19:05 WhyNotHugo

Cool. Maybe you could just have a quick look at the implementation and see if it looks ready to integrate or if I have misunderstood the process. I just now had a look at SVGWriter and it looks like I initialized my ascii writer the same way, using an upstream __init__ with callbacks as arguments from my local __init__.

You will notice that I am not doing anything in paint_module because I already computed the result in __init__.

Thank you

Mikael-Lovqvist avatar May 17 '25 19:05 Mikael-Lovqvist