Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Displaying With Text and ANSI

00:00 Text and ANSI files. Sometimes you may want to create a QR code that’s to be displayed in a terminal, which can only display text. Segno can do this by selecting TXT as the output format.

00:24 However, as you can see on screen, this output may be difficult to read as it defaults to using zeroes for the light areas and ones for the dark. This can be altered by using the dark and light arguments as seen here, using spaces for dark and hashes for light.

00:47 You may find that as seen on screen using two characters creates a QR code, which is closer to being a square, which will help with the readability. But depending on the monitor, color and font settings of your terminal, it can still be tricky to get these codes to read.

01:05 One solution to this is provided by Segno, and that’s using ANSI escape codes. This provides a more complex method of control in the terminal and allows the production of a QR code that will look like a graphic on any supported terminal.

01:20 To enable this format, change the file extension to .ans.

01:30 The ANSI mode only supports the border argument, but one issue you may find is that viewing the file may be less straightforward than a text file.

01:39 Opening it with a typical command line tool such as more will lead to a view of the escape characters themselves on macOS

01:55 or in Windows Terminal you’ll get some idea of the QR code, but it won’t be scannable.

02:07 On macOS and Linux, this incantation should open the file for viewing appropriately. But much more usefully, a simple piece of Python code will print it out easily to the terminal.

02:27 This Python script prints out the QR code line by line, opening up possibilities to use QR codes programmatically in the terminal.

02:45 Now that you’ve seen some of the alternative file formats that Segno has available, it’s time to look a little deeper into QR codes themselves and some of the other options that Segno has to offer.

Become a Member to join the conversation.