Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

print_tty() doesn't seem to work on non-black backgrounds #4

Closed
trhaynes opened this Issue · 7 comments

4 participants

@trhaynes

On a white terminal the qr.print_tty() function prints grey on the white background which doesn't seem to scan.

@SmileyChris
Owner

Darn... I wonder if there's an easy fix for that. Any ideas, @koenbollen ?

@utek

I think that changing "\x1b[1;47m" to "\x1b[1;7m" should help.
It would be black on white background and white on black background.

Or:
"\x1b[0m" to "\x1b[1;40m" - That one should work better.
Just remember to put out.write("\x1b[0m\n") before out.flush()

@SmileyChris
Owner

someone want to test that out on both a white and black background tty?

@utek
def print_tty(self, out=None):
        """
        Output the QR Code to a TTY (potentially useful for debugging).

        If the data has not been compiled yet, make it first.
        """
        if out is None:
            import sys
            out = sys.stdout

        if not out.isatty():
            raise OSError("Not a tty")

        if self.data_cache is None:
            self.make()

        modcount = self.modules_count
        out.write("\x1b[1;47m" + (" " * (modcount * 2 + 4)) + "\x1b[40m\n")
        for r in range(modcount):
            out.write("\x1b[1;47m  \x1b[40m")
            for c in range(modcount):
                if self.modules[r][c]:
                    out.write("  ")
                else:
                    out.write("\x1b[1;47m  \x1b[40m")
            out.write("\x1b[1;47m  \x1b[40m\n")
        out.write("\x1b[1;47m" + (" " * (modcount * 2 + 4)) + "\x1b[0m\n")
        out.flush()
@SmileyChris
Owner

Thanks @utek

In the future, a pull request is the way to go [using a branch]. They're pretty easy and means I can just click one button to merge ;)

E.g:
1. git remote add -f upstream git://github.com/lincolnloop/python-qrcode.git (-f saves us a git fetch upstream)
2. git checkout upstream/master -b tty-fix
3. Make changes then git commit -am "Make print_tty work on both black and white backgrounds. Fixes #4"
4. git push origin tty-fix
5. Go to github, switch to the tty-fix branch, click the pull request button.

@utek

Ok :) Next time I'll use pull requests. Thanks again for git hints :)

@koenbollen

Hey guys, when I woke up this morning it was already fixed. Nice.
For the record, I would've come up with the same fix.

Cheers,
Koen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.