Skip to content

Add QRCode.get_ascii() for string output - #437

Open
NixMelon wants to merge 4 commits into
lincolnloop:mainfrom
NixMelon:feat/get-ascii-435
Open

NixMelon wants to merge 4 commits into
lincolnloop:mainfrom
NixMelon:feat/get-ascii-435

Conversation

@NixMelon

Copy link
Copy Markdown

Summary

Closes #435.

This PR adds QRCode.get_ascii(), which returns the complete ASCII QR code representation as a string.

Previously, callers had to capture QRCode.print_ascii() output with io.StringIO or run the qr command through a subprocess. The new method allows terminal interfaces and other Python applications to use the generated text directly.

Changes

  • Add QRCode.get_ascii(tty=False, invert=False) -> str.
  • Preserve border, inversion, and TTY formatting behavior.
  • Automatically compile the QR matrix when necessary.
  • Refactor QRCode.print_ascii() to use get_ascii().
  • Preserve print_ascii() stream validation, output, and flushing behavior.
  • Replace the documented StringIO workaround with direct get_ascii() usage.
  • Add the new API to the changelog.

Testing

The tests cover:

  • returning a non-empty string;
  • exact output parity with print_ascii();
  • normal and inverted output;
  • zero and standard borders;
  • TTY escape codes;
  • automatic QR compilation;
  • repeated-call stability; and
  • output dimensions.

Focused test result:

10 passed, 30 deselected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get qr ascii

1 participant