mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix theme fallback
Now themes correctly use fallback values on TTY
This commit is contained in:
parent
17e44652b8
commit
6e4d00127b
@ -6,11 +6,11 @@ borders = "simple" # Alternatives are "none" and "outset"
|
|||||||
# Base colors are red, green, blue,
|
# Base colors are red, green, blue,
|
||||||
# cyan, magenta, yellow, white and black.
|
# cyan, magenta, yellow, white and black.
|
||||||
[colors]
|
[colors]
|
||||||
background = "#123456"
|
background = ["#923456", "magenta"]
|
||||||
# If the value is an array, the first valid color will be used.
|
# If the value is an array, the first valid color will be used.
|
||||||
# If the terminal doesn't support custom color,
|
# If the terminal doesn't support custom color,
|
||||||
# non-base colors will be skipped.
|
# non-base colors will be skipped.
|
||||||
shadow = ["#222222", "black"]
|
shadow = ["#222222", "blue"]
|
||||||
view = "#888888"
|
view = "#888888"
|
||||||
|
|
||||||
# Array and simple values have the same effect.
|
# Array and simple values have the same effect.
|
||||||
|
22
src/theme.rs
22
src/theme.rs
@ -168,7 +168,7 @@ pub struct ColorStyle {
|
|||||||
|
|
||||||
impl ColorStyle {
|
impl ColorStyle {
|
||||||
fn load(&mut self, table: &toml::Table) {
|
fn load(&mut self, table: &toml::Table) {
|
||||||
let mut new_id = 8;
|
let mut new_id = 16;
|
||||||
|
|
||||||
self.background.load(table, "background", &mut new_id);
|
self.background.load(table, "background", &mut new_id);
|
||||||
self.shadow.load(table, "shadow", &mut new_id);
|
self.shadow.load(table, "shadow", &mut new_id);
|
||||||
@ -273,6 +273,10 @@ impl Color {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *new_id >= ncurses::COLORS as i16 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let s = &value[1..];
|
let s = &value[1..];
|
||||||
let (l,max) = match s.len() {
|
let (l,max) = match s.len() {
|
||||||
6 => (2,255),
|
6 => (2,255),
|
||||||
@ -320,13 +324,6 @@ impl Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Loads the default theme, and returns its representation.
|
|
||||||
pub fn load_default() -> Theme {
|
|
||||||
let theme = Theme::default();
|
|
||||||
theme.apply();
|
|
||||||
theme
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Loads a theme file, and returns its representation if everything worked well.
|
/// Loads a theme file, and returns its representation if everything worked well.
|
||||||
///
|
///
|
||||||
/// The file should be a toml file. All fields are optional. Here is are the possible entries:
|
/// The file should be a toml file. All fields are optional. Here is are the possible entries:
|
||||||
@ -335,7 +332,7 @@ pub fn load_default() -> Theme {
|
|||||||
/// # Every field in a theme file is optional.
|
/// # Every field in a theme file is optional.
|
||||||
///
|
///
|
||||||
/// shadow = false
|
/// shadow = false
|
||||||
/// borders = "simple", # Alternatives are "none" and "outset"
|
/// borders = "simple" # Alternatives are "none" and "outset"
|
||||||
///
|
///
|
||||||
/// # Base colors are red, green, blue,
|
/// # Base colors are red, green, blue,
|
||||||
/// # cyan, magenta, yellow, white and black.
|
/// # cyan, magenta, yellow, white and black.
|
||||||
@ -383,6 +380,13 @@ pub fn load_theme<P: AsRef<Path>>(filename: P) -> Result<Theme,Error> {
|
|||||||
Ok(theme)
|
Ok(theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loads the default theme, and returns its representation.
|
||||||
|
pub fn load_default() -> Theme {
|
||||||
|
let theme = Theme::default();
|
||||||
|
theme.apply();
|
||||||
|
theme
|
||||||
|
}
|
||||||
|
|
||||||
/// Loads a hexadecimal code
|
/// Loads a hexadecimal code
|
||||||
fn load_hex(s: &str) -> i16 {
|
fn load_hex(s: &str) -> i16 {
|
||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user