|Pypi Installs| |Supported Python Versions|
|packagestatus|
{
The Python module contained is part of a broader set of scripts
For the shell scripts, if you source this from a shell session it will set and export ``COLORFGBG`` to ``0;15`` for dark backgrounds and ``15;0`` for light backgrounds which is
a convention used by some programs. Since I find this a little arcane, the program also sets and exports ``LC_DARK_BG`` to 1 for dark backgrounds and 0 for light. The ``LC_`` (locale) assists in some ssh configurations which often will let environment variables with that prefix get passed along and set to a remote ssh session.
From Python you can call ``term_background.is_dark_background()`` which returns a ``True`` if we think the background is dark.
The heuristics used is to try to query the background color using an `xterm control sequence <https://www.talisman.org/~erlkonig/documents/xterm-color-queries/>`_.
Many, but not all, terminals support this query. So as a fallback we query environment variable ``COLORFGBG`` and failing this we use some defaults for some known terminals set from the ``TERM`` environment variable. OSX has its own way of querying characteristics so we use that too if you are running on that OS.
When we can get pixel intensities of red, blue, and green values of the background, we can use that determine light and dark based the combined sum: zero values indicate an absense of a particular color and compare that with the values of the foreground.
You can set any of these environment variables to influence the output decision.
Many thanks to Thomas Dickey, Egmont Koblinger, and Gilles, for explanations (and code!) via `unix.stackexchange <http://unix.stackexchange.com/questions/245378/common-environment-variable-to-set-dark-or-light-terminal-background/245381#245381>`_. John Green had the idea to compare the foreground and background colors instead comparing the background against the midway gray color and implemented that change here.
Of course bugs and lacuna in this code are mine.
.. |Pypi Installs| image:: https://pepy.tech/badge/term-background
.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/term-background.svg
.. |packagestatus| image:: https://repology.org/badge/vertical-allrepos/python:term-background.svg :target: https://repology.org/project/python:term-background/versions
Raw data
{
"_id": null,
"home_page": "http://github.com/rocky/shell-term-background",
"name": "term-background",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Rocky Bernstein",
"author_email": "rb@dustyfeet.com",
"download_url": "https://files.pythonhosted.org/packages/24/18/7dc8c71e6fac31a34a94225cb4f5f912439b1ef825f2332b34d7119d83ee/term_background-1.0.2.tar.gz",
"platform": null,
"description": "|Pypi Installs| |Supported Python Versions|\n\n|packagestatus|\n\n{\n\nThe Python module contained is part of a broader set of scripts\n\nFor the shell scripts, if you source this from a shell session it will set and export ``COLORFGBG`` to ``0;15`` for dark backgrounds and ``15;0`` for light backgrounds which is\na convention used by some programs. Since I find this a little arcane, the program also sets and exports ``LC_DARK_BG`` to 1 for dark backgrounds and 0 for light. The ``LC_`` (locale) assists in some ssh configurations which often will let environment variables with that prefix get passed along and set to a remote ssh session.\n\nFrom Python you can call ``term_background.is_dark_background()`` which returns a ``True`` if we think the background is dark.\n\nThe heuristics used is to try to query the background color using an `xterm control sequence <https://www.talisman.org/~erlkonig/documents/xterm-color-queries/>`_.\n\nMany, but not all, terminals support this query. So as a fallback we query environment variable ``COLORFGBG`` and failing this we use some defaults for some known terminals set from the ``TERM`` environment variable. OSX has its own way of querying characteristics so we use that too if you are running on that OS.\n\nWhen we can get pixel intensities of red, blue, and green values of the background, we can use that determine light and dark based the combined sum: zero values indicate an absense of a particular color and compare that with the values of the foreground.\n\nYou can set any of these environment variables to influence the output decision.\n\nMany thanks to Thomas Dickey, Egmont Koblinger, and Gilles, for explanations (and code!) via `unix.stackexchange <http://unix.stackexchange.com/questions/245378/common-environment-variable-to-set-dark-or-light-terminal-background/245381#245381>`_. John Green had the idea to compare the foreground and background colors instead comparing the background against the midway gray color and implemented that change here.\n\nOf course bugs and lacuna in this code are mine.\n\n.. |Pypi Installs| image:: https://pepy.tech/badge/term-background\n.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/term-background.svg\n.. |packagestatus| image:: https://repology.org/badge/vertical-allrepos/python:term-background.svg :target: https://repology.org/project/python:term-background/versions\n\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Determine if shell has a light or dark background",
"version": "1.0.2",
"project_urls": {
"Homepage": "http://github.com/rocky/shell-term-background"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7ebcc90cad9f307e7b0746554fbaafae7392a5d2efac395106fc458710dca720",
"md5": "231755833cfc36c459e807607238165d",
"sha256": "9be7556851668f393d024aa9a251cc2018a5dde1d665bfe024412d3f03fb14a3"
},
"downloads": -1,
"filename": "term_background-1.0.2-py2-none-any.whl",
"has_sig": false,
"md5_digest": "231755833cfc36c459e807607238165d",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 12205,
"upload_time": "2024-10-10T16:50:11",
"upload_time_iso_8601": "2024-10-10T16:50:11.634081Z",
"url": "https://files.pythonhosted.org/packages/7e/bc/c90cad9f307e7b0746554fbaafae7392a5d2efac395106fc458710dca720/term_background-1.0.2-py2-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8237641ddef6347f9fd42638743dc745857ff1fb682dd7d1a7262de494dda259",
"md5": "85679ea2f2e47366ab6a67f44a08b38c",
"sha256": "e894ac4af47cdf2b5d5fab64470f912972f306af011f21687644d70d28698cc5"
},
"downloads": -1,
"filename": "term_background-1.0.2-py310-none-any.whl",
"has_sig": false,
"md5_digest": "85679ea2f2e47366ab6a67f44a08b38c",
"packagetype": "bdist_wheel",
"python_version": "py310",
"requires_python": null,
"size": 12194,
"upload_time": "2024-10-10T16:50:12",
"upload_time_iso_8601": "2024-10-10T16:50:12.598169Z",
"url": "https://files.pythonhosted.org/packages/82/37/641ddef6347f9fd42638743dc745857ff1fb682dd7d1a7262de494dda259/term_background-1.0.2-py310-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1a36e0ccd50bdc44a68ea04233a3bec64238ebcdd9e1e0158e31adf141c84496",
"md5": "f549e0177f8b281d053c6883909f7775",
"sha256": "c80af48eea39bc19d134e52923264d3c3ad0b14fb33cd6b9ba9ad1eb45cea754"
},
"downloads": -1,
"filename": "term_background-1.0.2-py311-none-any.whl",
"has_sig": false,
"md5_digest": "f549e0177f8b281d053c6883909f7775",
"packagetype": "bdist_wheel",
"python_version": "py311",
"requires_python": null,
"size": 5335,
"upload_time": "2024-10-10T16:50:13",
"upload_time_iso_8601": "2024-10-10T16:50:13.426000Z",
"url": "https://files.pythonhosted.org/packages/1a/36/e0ccd50bdc44a68ea04233a3bec64238ebcdd9e1e0158e31adf141c84496/term_background-1.0.2-py311-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "14b6b5b5b397fe5e302176cdaa8b446e7d387272f0962c55ab4f4404cc12b7bc",
"md5": "c35f26636eb1011f07feb66463c1c7e2",
"sha256": "6b1f07bd95600786a671753a179e1ab38d971cac1a31758ab39968262fd4f259"
},
"downloads": -1,
"filename": "term_background-1.0.2-py312-none-any.whl",
"has_sig": false,
"md5_digest": "c35f26636eb1011f07feb66463c1c7e2",
"packagetype": "bdist_wheel",
"python_version": "py312",
"requires_python": null,
"size": 12375,
"upload_time": "2024-10-10T16:50:14",
"upload_time_iso_8601": "2024-10-10T16:50:14.670523Z",
"url": "https://files.pythonhosted.org/packages/14/b6/b5b5b397fe5e302176cdaa8b446e7d387272f0962c55ab4f4404cc12b7bc/term_background-1.0.2-py312-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9fee42b93f7120f1fbf30136deec18296db119f03eb2b5d7a93bba936b10f023",
"md5": "23f6373dc41a646da78a90e9abaa0cf2",
"sha256": "ff955ca76b72d3928598149aa8b5db942204904c6b45f3cc3c050ba4996db4b7"
},
"downloads": -1,
"filename": "term_background-1.0.2-py34-none-any.whl",
"has_sig": false,
"md5_digest": "23f6373dc41a646da78a90e9abaa0cf2",
"packagetype": "bdist_wheel",
"python_version": "py34",
"requires_python": null,
"size": 12179,
"upload_time": "2024-10-10T16:51:24",
"upload_time_iso_8601": "2024-10-10T16:51:24.423871Z",
"url": "https://files.pythonhosted.org/packages/9f/ee/42b93f7120f1fbf30136deec18296db119f03eb2b5d7a93bba936b10f023/term_background-1.0.2-py34-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "31ce9525eab178887653ed08568ef45d852ee8a7fc7103aa674b69ed59d63a7c",
"md5": "d6e47e0d8421cb73851797d887bc01e6",
"sha256": "8b9836d90dd98f25f46afd24ed6e286ccd16d56f5dbb5d300d1d969fa2aceb2a"
},
"downloads": -1,
"filename": "term_background-1.0.2-py35-none-any.whl",
"has_sig": false,
"md5_digest": "d6e47e0d8421cb73851797d887bc01e6",
"packagetype": "bdist_wheel",
"python_version": "py35",
"requires_python": null,
"size": 12176,
"upload_time": "2024-10-10T16:51:25",
"upload_time_iso_8601": "2024-10-10T16:51:25.868730Z",
"url": "https://files.pythonhosted.org/packages/31/ce/9525eab178887653ed08568ef45d852ee8a7fc7103aa674b69ed59d63a7c/term_background-1.0.2-py35-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "59f873b31fb3ec42d3b8f4f0ee27e86fac140171620f9f05420654e8cc86bb42",
"md5": "e64a480c7da34ebca8fe024d638d639b",
"sha256": "540e48ec34fea7edf2482d23ede5ad359c1587f1c49bb7a23a35a5d47455c99d"
},
"downloads": -1,
"filename": "term_background-1.0.2-py36-none-any.whl",
"has_sig": false,
"md5_digest": "e64a480c7da34ebca8fe024d638d639b",
"packagetype": "bdist_wheel",
"python_version": "py36",
"requires_python": null,
"size": 12213,
"upload_time": "2024-10-10T16:51:26",
"upload_time_iso_8601": "2024-10-10T16:51:26.983813Z",
"url": "https://files.pythonhosted.org/packages/59/f8/73b31fb3ec42d3b8f4f0ee27e86fac140171620f9f05420654e8cc86bb42/term_background-1.0.2-py36-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2f77db99756367b5ef00418fdc14e3e5fc521266203ee89d8d3bdcc3bfc1b892",
"md5": "cbad674553b60609375da2518f3e2e1f",
"sha256": "71d029eceb97313586324b16cfecf313478fa9cb8ed1379bbd3d2c81f3a8a64d"
},
"downloads": -1,
"filename": "term_background-1.0.2-py37-none-any.whl",
"has_sig": false,
"md5_digest": "cbad674553b60609375da2518f3e2e1f",
"packagetype": "bdist_wheel",
"python_version": "py37",
"requires_python": null,
"size": 12193,
"upload_time": "2024-10-10T16:51:28",
"upload_time_iso_8601": "2024-10-10T16:51:28.601983Z",
"url": "https://files.pythonhosted.org/packages/2f/77/db99756367b5ef00418fdc14e3e5fc521266203ee89d8d3bdcc3bfc1b892/term_background-1.0.2-py37-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b4919898424d425d8b6a51d64419a260b48cb8767ae374d90ebf8fd32b117b48",
"md5": "adf79b605020b02942802870b545f4eb",
"sha256": "3f4c2c4f84398d091329142d6b16e139a8c136c8c66af1c554fabcafadc7738a"
},
"downloads": -1,
"filename": "term_background-1.0.2-py38-none-any.whl",
"has_sig": false,
"md5_digest": "adf79b605020b02942802870b545f4eb",
"packagetype": "bdist_wheel",
"python_version": "py38",
"requires_python": null,
"size": 12198,
"upload_time": "2024-10-10T16:51:29",
"upload_time_iso_8601": "2024-10-10T16:51:29.795585Z",
"url": "https://files.pythonhosted.org/packages/b4/91/9898424d425d8b6a51d64419a260b48cb8767ae374d90ebf8fd32b117b48/term_background-1.0.2-py38-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "03e20b7a43b2f0c87807de51045093424297172e1644faca3ccb7ecf79fb3ac0",
"md5": "13922ec079a785342f4825be29616a4c",
"sha256": "029291ba62573c637227801ecd43cb7388355610ffb7710d68a9406be210be80"
},
"downloads": -1,
"filename": "term_background-1.0.2-py39-none-any.whl",
"has_sig": false,
"md5_digest": "13922ec079a785342f4825be29616a4c",
"packagetype": "bdist_wheel",
"python_version": "py39",
"requires_python": null,
"size": 12214,
"upload_time": "2024-10-10T16:51:30",
"upload_time_iso_8601": "2024-10-10T16:51:30.518214Z",
"url": "https://files.pythonhosted.org/packages/03/e2/0b7a43b2f0c87807de51045093424297172e1644faca3ccb7ecf79fb3ac0/term_background-1.0.2-py39-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "24187dc8c71e6fac31a34a94225cb4f5f912439b1ef825f2332b34d7119d83ee",
"md5": "e5f44643fa6f3c37686018e8a30e9b7a",
"sha256": "96dcba8b664f272c7f1db183be70c1825e936990b65566999583f14ca326c75c"
},
"downloads": -1,
"filename": "term_background-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "e5f44643fa6f3c37686018e8a30e9b7a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12320,
"upload_time": "2024-10-10T16:52:32",
"upload_time_iso_8601": "2024-10-10T16:52:32.949436Z",
"url": "https://files.pythonhosted.org/packages/24/18/7dc8c71e6fac31a34a94225cb4f5f912439b1ef825f2332b34d7119d83ee/term_background-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-10 16:52:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rocky",
"github_project": "shell-term-background",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "term-background"
}