{"id":20887955,"url":"https://github.com/canop/terminal-light","last_synced_at":"2025-04-07T11:04:15.772Z","repository":{"id":44556449,"uuid":"394185793","full_name":"Canop/terminal-light","owner":"Canop","description":"Tells you whether the terminal is \"dark\" or \"light\"","archived":false,"fork":false,"pushed_at":"2024-10-15T08:39:47.000Z","size":91,"stargazers_count":25,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T10:01:37.192Z","etag":null,"topics":["hacktoberfest","rust","terminal"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Canop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-09T07:02:53.000Z","updated_at":"2025-01-29T11:46:04.000Z","dependencies_parsed_at":"2024-01-15T19:25:15.603Z","dependency_job_id":"f5a4050f-5d73-4ee1-be77-f5c5487f314c","html_url":"https://github.com/Canop/terminal-light","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.032258064516129004","last_synced_commit":"6e44a3a5fd4a9a4b169e9049520e555b654a8c6c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fterminal-light","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fterminal-light/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fterminal-light/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fterminal-light/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Canop","download_url":"https://codeload.github.com/Canop/terminal-light/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640461,"owners_count":20971557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","rust","terminal"],"created_at":"2024-11-18T08:23:31.133Z","updated_at":"2025-04-07T11:04:15.751Z","avatar_url":"https://github.com/Canop.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![MIT][s2]][l2] [![Latest Version][s1]][l1] [![docs][s3]][l3] [![Chat on Miaou][s4]][l4]\n\n[s1]: https://img.shields.io/crates/v/terminal-light.svg\n[l1]: https://crates.io/crates/terminal-light\n\n[s2]: https://img.shields.io/badge/license-MIT-blue.svg\n[l2]: LICENSE\n\n[s3]: https://docs.rs/terminal-light/badge.svg\n[l3]: https://docs.rs/terminal-light/\n\n[s4]: https://miaou.dystroy.org/static/shields/room.svg\n[l4]: https://miaou.dystroy.org/3\n\n# terminal-light\n\nThis crate answers the question *\"Is the terminal dark or light?\"*.\n\nIt provides\n\n* the background color, either as RGB or ANSI\n* the background color's luma, which varies from 0 (black) to 1 (white)\n\nA use case in a TUI is to determine what set of colors would be most suitable depending on the terminal's background:\n\n```\nlet should_use_light_skin = terminal_light::luma()\n    .map_or(false, |luma| luma \u003e 0.6);\n```\n\nIf you have very specialized skins, you may choose a more precise switch:\n\n```\nmatch terminal_light::luma() {\n    Ok(luma) if luma \u003e 0.85 =\u003e {\n        // Use a \"light mode\" skin.\n    }\n    Ok(luma) if luma \u003c 0.2 =\u003e {\n        // Use a \"dark mode\" skin.\n    }\n    _ =\u003e {\n        // Either we couldn't determine the mode or it's kind of medium.\n        // We should use an itermediate skin, or one defining the background.\n    }\n}\n```\n\nSee the included example:\n\n![dark](doc/dark.png)\n\n![light](doc/light.png)\n\n\n# Strategies\n\nHere are the various strategies automatically used by terminal-light to answer the big question:\n\n## `$COLORFGBG` strategy\n\nThis environment variable is set by some terminals, like konsole or the rxvt family.\nIt can also be set by users.\nIts value is like `15;0` where the second number is the ANSI code for the background color.\n\nUpsides:\n\n* querying an env variable is a fast operation\n\nDownsides:\n\n* this env variable isn't always immediately updated when you change the color of the terminal\n* the value isn't precise: `0` is \"dark\" and `15` is \"light\" but the real RGB color is uncertain as the low ANSI codes are often modified by the user\n\n## \"Dynamic colors\" OSC escape sequence strategy\n\nModern terminals implement this xterm extension: a query making it possible to know the background color as RGB.\n\nTerminal-light sends the query on `stdout`, waits for the answer on `stdin` with a timeout of 20ms, then parses this answer.\n\nUpsides:\n\n* this works well on all tested unix terminals, including on MacOs\n* the value is precise (RGB)\n* the value is up to date when it's available\n\nDownsides:\n\n* waiting for stdin with a timeout isn't implemented on Windows in this crate (help welcome)\n* this isn't instant, a delay of 10 ms to get the answer isn't unusual\n* if a not compatible terminal doesn't answer at all, we're waiting for 20ms\n* it may fail on some terminal multiplexers\n\n## Global strategy used by Terminal-light\n\n1. if we're on a unix-like platform, we try the escape sequence strategy\n2. if it failed or we're not on unix, we try the `$COLORFGBG` strategy\n3. without a solution, we return a `TlError::Unsupported` error\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanop%2Fterminal-light","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcanop%2Fterminal-light","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanop%2Fterminal-light/lists"}