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

Closed
trhaynes opened this Issue Jan 17, 2012 · 7 comments

Comments

Projects
None yet
4 participants

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

Owner

SmileyChris commented Jan 17, 2012

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

utek commented Jan 17, 2012

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()

Owner

SmileyChris commented Jan 17, 2012

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

utek commented Jan 17, 2012

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()
Owner

SmileyChris commented Jan 17, 2012

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 commented Jan 17, 2012

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

@utek utek added a commit to utek/python-qrcode that referenced this issue Jan 17, 2012

@utek utek Make print_tty work on both black and white backgrounds. Fixes #4 ed4cc43
Contributor

koenbollen commented Jan 18, 2012

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