-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support non truecolor terminal
- Loading branch information
Showing
10 changed files
with
63 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ ratatui = "0.23.0" | |
crossterm = "0.27.0" | ||
regex = "1.10.1" | ||
itertools = "0.11.0" | ||
lazy_static = "1.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,39 @@ | ||
use crossterm::style::available_color_count; | ||
use ratatui::style::Color; | ||
use std::env; | ||
|
||
// pub const BORDER: Color = Color::Rgb(220, 215, 186); | ||
// pub const TEXT: Color = Color::Rgb(220, 215, 186); | ||
pub const BORDER: Color = Color::Rgb(242, 232, 207); | ||
pub const TEXT_DARK: Color = Color::Rgb(0, 18, 25); | ||
pub const TEXT_LIGHT: Color = Color::Rgb(242, 232, 207); | ||
pub const BACKGROUND_DARK: Color = Color::Rgb(0, 18, 25); | ||
pub const BACKGROUND_LIGHT: Color = Color::Rgb(242, 232, 207); | ||
pub const GREEN: Color = Color::Rgb(56, 176, 0); | ||
pub const RED: Color = Color::Rgb(193, 18, 30); | ||
pub const BLUE: Color = Color::Rgb(72, 202, 228); | ||
lazy_static! { | ||
pub static ref BORDER: Color = | ||
color(Color::Rgb(242, 232, 207), Color::Indexed(255), Color::White); | ||
pub static ref TEXT_DARK: Color = | ||
color(Color::Rgb(0, 18, 25), Color::Indexed(233), Color::Black); | ||
pub static ref TEXT_LIGHT: Color = | ||
color(Color::Rgb(242, 232, 207), Color::Indexed(255), Color::White); | ||
pub static ref BACKGROUND_DARK: Color = | ||
color(Color::Rgb(0, 18, 25), Color::Indexed(233), Color::Black); | ||
pub static ref BACKGROUND_LIGHT: Color = | ||
color(Color::Rgb(242, 232, 207), Color::Indexed(255), Color::White); | ||
pub static ref GREEN: Color = color(Color::Rgb(56, 176, 0), Color::Indexed(34), Color::Green); | ||
pub static ref RED: Color = color(Color::Rgb(193, 18, 30), Color::Indexed(160), Color::Red); | ||
pub static ref BLUE: Color = color(Color::Rgb(72, 202, 228), Color::Indexed(27), Color::Blue); | ||
} | ||
|
||
fn color(truecolor: Color, color256: Color, fallback: Color) -> Color { | ||
if truecolor_support() { | ||
truecolor | ||
} else if color256_support() { | ||
color256 | ||
} else { | ||
fallback | ||
} | ||
} | ||
|
||
fn truecolor_support() -> bool { | ||
let colorterm = env::var("COLORTERM").unwrap_or_default(); | ||
|
||
colorterm == "truecolor" || colorterm == "24bit" | ||
} | ||
|
||
fn color256_support() -> bool { | ||
available_color_count() == 256 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters