Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 24-bit "truecolor" support, tweaked font paths. #18

Merged
merged 5 commits into from
Jul 1, 2021

Conversation

jaysonlarose
Copy link
Contributor

Created classes ColorStringTrue, fgtrue, bgtrue, highlighttrue, and complementtrue to color.py, in order to support the increasing number of terminals that support full 24-bit color.

Also made the following changes to text.py:

  • Moved the roots font directory search list that was embedded into get_font_files() out to font_roots, so that it can be modified/monkeypatched externally.
  • Added ~/.local/share/fonts to the font directory search list.

so it can be modified externally.

Also added ~/.local/share/fonts to the search list.
@jart
Copy link
Owner

jart commented May 14, 2020

Pressing merge not possible because xterm256 practices need to change.

@jaysonlarose
Copy link
Contributor Author

Is there anything I can do on my end to resolve this?

@jart
Copy link
Owner

jart commented May 14, 2020

@jaysonlarose
Copy link
Contributor Author

I see your handcrafted scene-era x86 assembly demo written in 2015, and raise you a technical primer for a 1960's era computer presented in 2017.

https://www.youtube.com/watch?v=xx7Lfh5SKUQ

@jart
Copy link
Owner

jart commented May 14, 2020

I'm a fan of Margaret Hamilton's code. I also like to implement telecom systems so they DDOS NASA when entering a failure state.

@jaysonlarose
Copy link
Contributor Author

I must confess, I get the first reference (I love this picture, almost as much as I love this clip of Delia Derbyshire beatmatching on washing machine-sized reel-to-reel machines), but the second eludes me... Unless, of course, you're truly saying that you like to implement telecom systems so they DDOS NASA when entering a failure state, in which case I'd have to say you're pretty hardcore

@jaysonlarose
Copy link
Contributor Author

In all seriousness, though, why is this pull request being rejected? I thought I did a fairly decent job of following the existing code style, and the extent of the changes is pretty small. The only thing I didn't do was implement any sort of check for the COLORTERM environment variable, as it seems not all terminals that support 24-bit color set this variable accordingly.

Or is this some sort of "256 colors ought to be enough for everybody" thing?

@jart
Copy link
Owner

jart commented Jun 14, 2020

I'm happy to accept your work. Thank you for your contribution. Do you know why Travis is failing? Also we all love NASA which is why no one would DDOS a telecommunications system that was known to have such a deterrent in place. It also encourages goofballs such as myself to do the best engineering possible. For example, would trivial NPM projects have 13,000 dependencies if developers knew that the consequences of being lazy could potentially impact the brave young men and women risking their lives to help humanity explore the final frontier?

@jart
Copy link
Owner

jart commented Jun 14, 2020

As for 256 colors being enough for everyone, I've been mostly crossing my fingers hoping someone will come along and implement something that looks like this:

parrots256

That's probably not as good as the 8088 MPH demo. Making it happen turned out to be exceedingly difficult. It requires a certain degree of mastery over the parts of the photon spectrum that computers are allowed to use:

photoreceptiveness

@jaysonlarose
Copy link
Contributor Author

Apparently python 2.x doesn't like a thing I was doing with asterisks.... It's not a huge change, I'll push a new revision up now.

@jart
Copy link
Owner

jart commented Jun 14, 2020

Thank you. I still use Python2 so it's much appreciated.

@jaysonlarose
Copy link
Contributor Author

There were some other errors I saw in Travis related to sphinx and it no longer supporting python 2.6, but those seem to have gone away.

I've been fortunate enough to have been able to make a clean break from python 2.x, for the most part... well, except for GIMP. I had a couple of scripts I wrote in python-fu, and didn't realize until just last week that since that hasn't been migrated to 3.x, Ubuntu basically just plain didn't include support for python-fu. D'oh.

@jaysonlarose
Copy link
Contributor Author

That there is a masterpiece of terminal character dithering.

Here's a bit of "brute force and ignorance" I cobbled together using 24-bit color codes and liberal use of "█":

@jaysonlarose
Copy link
Contributor Author

Here's a gist for doing the above that works under python2 and python3. (Birds not included)

https://gist.github.com/jaysonlarose/154b0086f77175b5f422714d77d2b127

@jason-green-io
Copy link

Now do it with unicode half blocks. Please.

@jaysonlarose
Copy link
Contributor Author

@jason-green-io — Half blocks for you. Because I like your name ;)

https://gist.github.com/jaysonlarose/fc86aa38360910669e7762c5b49c7923

Maybe 2021 is the year @jart accepts my pull request! :D

  that — if it's installed — wcwidth.wcswidth will be used for
calculating lengths. Only for python 3.x, though.
@jaysonlarose
Copy link
Contributor Author

Since I've been dealing with some stuff that requires me to calculate the in-terminal width of colored unicode text, I've added in a clause so that the fabulous.color.ColorString base class will use the wcwidth module for determining string lengths, if it's installed.

I also added a fix for how ColorString calculates the length of bytes objects under Python 3. I mean, it's bad form to treat bytes objects like they're strings without passing them through .decode() under Python 3 to begin with, but at least you'll get back a length that reflects reality:

old behavior:

>>> print(len(fabulous.color.fg256("green", b"binary bee")))
10
>>> print(fabulous.color.fg256("green", b"binary bee"))
b'binary bee'

corrected behavior:

>>> print(len(fabulous.color.fg256("green", b"binary bee")))
13
>>> print(fabulous.color.fg256("green", b"binary bee"))
b'binary bee'

All of these changes are specific to Python 3.x. I left behavior under Python 2.x unchanged.

@jaysonlarose
Copy link
Contributor Author

It's me again!

I've added a .join() method to fabulous.color.ColorString, so now you can do this:

from fabulous.color import *
l = [
    fg256("green", "napster good"),
    fg256("red", "fire bad"),
]
print(plain(" ").join(l))

@jart
Copy link
Owner

jart commented Jul 1, 2021

Thank you. Let's get this merged and pushed to pypi.

@jart jart merged commit 2ec4476 into jart:master Jul 1, 2021
@jart
Copy link
Owner

jart commented Jul 1, 2021

New release posted here: https://github.com/jart/fabulous/releases/tag/0.4.0

I'm having the darndest time getting it to upload to pypi. I put the appropriate values in ~/.pypirc but I'm getting:

$ python setup.py sdist upload
...
Creating tar archive
removing 'fabulous-0.4.0' (and everything under it)
running upload
Submitting dist/fabulous-0.4.0.tar.gz to https://upload.pypi.org/legacy/
Upload failed (403): Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for more information.
error: Upload failed (403): Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for more information.

Do you have any idea?

# my ~/.pypirc
[pypi]
username = __token__
password = pypi-AxEIcHlw....etc

@cjrh
Copy link

cjrh commented Jul 1, 2021

IIRC upload no longer works on PyPI, twine is required to upload packages: https://twine.readthedocs.io/en/latest/

@jart
Copy link
Owner

jart commented Jul 1, 2021

I tried installing that and I just couldn't believe that it needed rust as a build-time dependency and that no binary releases were available. Surely there's some other way?

@cjrh
Copy link

cjrh commented Jul 2, 2021

It's probably the cryptography package where you're hitting the problem. That change (rust) caused a fair bit of controversy on the cryptography project tracker: pyca/cryptography#5771

What they recommend is to first upgrade pip before doing the installation: https://github.com/pyca/cryptography/blob/main/docs/installation.rst

The easiest way to upgrade pip is to make a virtualenv and update it in there, rather than trying to update your system pip (I don't know how your python is set up).

You should be able to install a binary release, if your system matches one of these wheel specs:

https://pypi.org/project/cryptography/#files

If there isn't a matching wheel for your system then yeah, it's a hard road.

p.s. while I have your attention, just let me say your work on redbean is extraordinary, I am in awe.

@jart
Copy link
Owner

jart commented Jul 2, 2021

I've done as you recommended. I'm proud to say we now have https://pypi.org/project/fabulous/0.4.0/ Enjoy!

That's interesting to hear. I'm saddened this kind of library wouldn't target manylinux1. redbean release binaries run on RHEL5. I'm glad you like it! Seeing how difficult it was to distribute native binaries for tensorflow was one of the reasons why I wrote Cosmopolitan Libc. I want the project to eventually evolve in a direction where it can support Python too. We've managed to port python2.7 so far, which can now run as an APE binary. In the future we'll make it able to build Actually Portable Shared Objects for Python extensions specifically that will reduce much of the toil we've seen. One way you can support these efforts is by becoming a github sponsor.

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.

4 participants