use crate::style::{properties::*, Style};
impl Style {
pub fn inherit(mut self, other: Style) -> Self {
let property_keys = [
BOLD_KEY,
ITALIC_KEY,
UNDERLINE_KEY,
STRIKETHROUGH_KEY,
REVERSE_KEY,
BLINK_KEY,
FAINT_KEY,
UNDERLINE_SPACES_KEY,
STRIKETHROUGH_SPACES_KEY,
COLOR_WHITESPACE_KEY,
FOREGROUND_KEY,
BACKGROUND_KEY,
WIDTH_KEY,
HEIGHT_KEY,
ALIGN_HORIZONTAL_KEY,
ALIGN_VERTICAL_KEY,
BORDER_STYLE_KEY,
BORDER_TOP_KEY,
BORDER_RIGHT_KEY,
BORDER_BOTTOM_KEY,
BORDER_LEFT_KEY,
BORDER_TOP_FOREGROUND_KEY,
BORDER_RIGHT_FOREGROUND_KEY,
BORDER_BOTTOM_FOREGROUND_KEY,
BORDER_LEFT_FOREGROUND_KEY,
BORDER_TOP_BACKGROUND_KEY,
BORDER_RIGHT_BACKGROUND_KEY,
BORDER_BOTTOM_BACKGROUND_KEY,
BORDER_LEFT_BACKGROUND_KEY,
INLINE_KEY,
MAX_WIDTH_KEY,
MAX_HEIGHT_KEY,
TAB_WIDTH_KEY,
TRANSFORM_KEY,
];
for &key in &property_keys {
if !other.is_set(key) {
continue; }
if matches!(
key,
PADDING_TOP_KEY
| PADDING_RIGHT_KEY
| PADDING_BOTTOM_KEY
| PADDING_LEFT_KEY
| MARGIN_TOP_KEY
| MARGIN_RIGHT_KEY
| MARGIN_BOTTOM_KEY
| MARGIN_LEFT_KEY
) {
continue;
}
if key == BACKGROUND_KEY
&& !self.is_set(MARGIN_BACKGROUND_KEY)
&& !other.is_set(MARGIN_BACKGROUND_KEY)
{
if let Some(ref bg) = other.bg_color {
self.margin_bg_color = Some(bg.clone());
self.set_prop(MARGIN_BACKGROUND_KEY);
}
}
if self.is_set(key) {
continue; }
match key {
BOLD_KEY => {
self.set_attr(ATTR_BOLD, other.get_attr(ATTR_BOLD));
self.set_prop(key);
}
ITALIC_KEY => {
self.set_attr(ATTR_ITALIC, other.get_attr(ATTR_ITALIC));
self.set_prop(key);
}
UNDERLINE_KEY => {
self.set_attr(ATTR_UNDERLINE, other.get_attr(ATTR_UNDERLINE));
self.set_prop(key);
}
STRIKETHROUGH_KEY => {
self.set_attr(ATTR_STRIKETHROUGH, other.get_attr(ATTR_STRIKETHROUGH));
self.set_prop(key);
}
REVERSE_KEY => {
self.set_attr(ATTR_REVERSE, other.get_attr(ATTR_REVERSE));
self.set_prop(key);
}
BLINK_KEY => {
self.set_attr(ATTR_BLINK, other.get_attr(ATTR_BLINK));
self.set_prop(key);
}
FAINT_KEY => {
self.set_attr(ATTR_FAINT, other.get_attr(ATTR_FAINT));
self.set_prop(key);
}
UNDERLINE_SPACES_KEY => {
self.set_attr(ATTR_UNDERLINE_SPACES, other.get_attr(ATTR_UNDERLINE_SPACES));
self.set_prop(key);
}
STRIKETHROUGH_SPACES_KEY => {
self.set_attr(
ATTR_STRIKETHROUGH_SPACES,
other.get_attr(ATTR_STRIKETHROUGH_SPACES),
);
self.set_prop(key);
}
COLOR_WHITESPACE_KEY => {
self.set_attr(ATTR_COLOR_WHITESPACE, other.get_attr(ATTR_COLOR_WHITESPACE));
self.set_prop(key);
}
FOREGROUND_KEY => {
self.fg_color = other.fg_color.clone();
self.set_prop(key);
}
BACKGROUND_KEY => {
self.bg_color = other.bg_color.clone();
self.set_prop(key);
}
WIDTH_KEY => {
self.width = other.width;
self.set_prop(key);
}
HEIGHT_KEY => {
self.height = other.height;
self.set_prop(key);
}
ALIGN_HORIZONTAL_KEY => {
self.align_horizontal = other.align_horizontal;
self.set_prop(key);
}
ALIGN_VERTICAL_KEY => {
self.align_vertical = other.align_vertical;
self.set_prop(key);
}
BORDER_STYLE_KEY => {
self.border_style = other.border_style;
self.set_prop(key);
}
BORDER_TOP_KEY => {
self.set_attr(ATTR_BORDER_TOP, other.get_attr(ATTR_BORDER_TOP));
self.set_prop(key);
}
BORDER_RIGHT_KEY => {
self.set_attr(ATTR_BORDER_RIGHT, other.get_attr(ATTR_BORDER_RIGHT));
self.set_prop(key);
}
BORDER_BOTTOM_KEY => {
self.set_attr(ATTR_BORDER_BOTTOM, other.get_attr(ATTR_BORDER_BOTTOM));
self.set_prop(key);
}
BORDER_LEFT_KEY => {
self.set_attr(ATTR_BORDER_LEFT, other.get_attr(ATTR_BORDER_LEFT));
self.set_prop(key);
}
BORDER_TOP_FOREGROUND_KEY => {
self.border_top_fg_color = other.border_top_fg_color.clone();
self.set_prop(key);
}
BORDER_RIGHT_FOREGROUND_KEY => {
self.border_right_fg_color = other.border_right_fg_color.clone();
self.set_prop(key);
}
BORDER_BOTTOM_FOREGROUND_KEY => {
self.border_bottom_fg_color = other.border_bottom_fg_color.clone();
self.set_prop(key);
}
BORDER_LEFT_FOREGROUND_KEY => {
self.border_left_fg_color = other.border_left_fg_color.clone();
self.set_prop(key);
}
BORDER_TOP_BACKGROUND_KEY => {
self.border_top_bg_color = other.border_top_bg_color.clone();
self.set_prop(key);
}
BORDER_RIGHT_BACKGROUND_KEY => {
self.border_right_bg_color = other.border_right_bg_color.clone();
self.set_prop(key);
}
BORDER_BOTTOM_BACKGROUND_KEY => {
self.border_bottom_bg_color = other.border_bottom_bg_color.clone();
self.set_prop(key);
}
BORDER_LEFT_BACKGROUND_KEY => {
self.border_left_bg_color = other.border_left_bg_color.clone();
self.set_prop(key);
}
INLINE_KEY => {
self.set_attr(ATTR_INLINE, other.get_attr(ATTR_INLINE));
self.set_prop(key);
}
MAX_WIDTH_KEY => {
self.max_width = other.max_width;
self.set_prop(key);
}
MAX_HEIGHT_KEY => {
self.max_height = other.max_height;
self.set_prop(key);
}
TAB_WIDTH_KEY => {
self.tab_width = other.tab_width;
self.set_prop(key);
}
TRANSFORM_KEY => {
self.transform = other.transform.clone();
self.set_prop(key);
}
_ => {} }
}
self
}
#[deprecated(note = "Use clone() or assignment instead")]
pub fn copy(&self) -> Self {
self.clone()
}
}