MCPcopy Index your code
hub / github.com/lincolnloop/python-qrcode / print_tty

Method print_tty

qrcode/main.py:256–284  ·  view source on GitHub ↗

Output the QR Code only using TTY colors. If the data has not been compiled yet, make it first.

(self, out=None)

Source from the content-addressed store, hash-verified

254 return pattern
255
256 def print_tty(self, out=None):
257 """
258 Output the QR Code only using TTY colors.
259
260 If the data has not been compiled yet, make it first.
261 """
262 if out is None:
263 import sys
264
265 out = sys.stdout
266
267 if not out.isatty():
268 raise OSError("Not a tty")
269
270 if self.data_cache is None:
271 self.make()
272
273 modcount = self.modules_count
274 out.write("\x1b[1;47m" + (" " * (modcount * 2 + 4)) + "\x1b[0m\n")
275 for r in range(modcount):
276 out.write("\x1b[1;47m \x1b[40m")
277 for c in range(modcount):
278 if self.modules[r][c]:
279 out.write(" ")
280 else:
281 out.write("\x1b[1;47m \x1b[40m")
282 out.write("\x1b[1;47m \x1b[0m\n")
283 out.write("\x1b[1;47m" + (" " * (modcount * 2 + 4)) + "\x1b[0m\n")
284 out.flush()
285
286 def print_ascii(self, out=None, tty=False, invert=False):
287 """

Callers 1

test_print_ttyFunction · 0.95

Calls 2

makeMethod · 0.95
writeMethod · 0.80

Tested by 1

test_print_ttyFunction · 0.76