GithubHelp home page GithubHelp logo

Comments (7)

SmileyChris avatar SmileyChris commented on June 30, 2024

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

from python-qrcode.

utek avatar utek commented on June 30, 2024

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

from python-qrcode.

SmileyChris avatar SmileyChris commented on June 30, 2024

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

from python-qrcode.

utek avatar utek commented on June 30, 2024
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()

from python-qrcode.

SmileyChris avatar SmileyChris commented on June 30, 2024

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.

from python-qrcode.

utek avatar utek commented on June 30, 2024

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

from python-qrcode.

koenbollen avatar koenbollen commented on June 30, 2024

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

from python-qrcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.