|
|
@ -25,62 +25,52 @@ impl Default for CursorKind {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Margin {
|
|
|
|
pub struct Margin {
|
|
|
|
pub left: u16,
|
|
|
|
pub horizontal: u16,
|
|
|
|
pub right: u16,
|
|
|
|
pub vertical: u16,
|
|
|
|
pub top: u16,
|
|
|
|
|
|
|
|
pub bottom: u16,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Margin {
|
|
|
|
impl Margin {
|
|
|
|
pub fn none() -> Self {
|
|
|
|
pub fn none() -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
left: 0,
|
|
|
|
horizontal: 0,
|
|
|
|
right: 0,
|
|
|
|
vertical: 0,
|
|
|
|
top: 0,
|
|
|
|
|
|
|
|
bottom: 0,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Set uniform margin for all sides.
|
|
|
|
/// Set uniform margin for all sides.
|
|
|
|
pub fn all(value: u16) -> Self {
|
|
|
|
pub const fn all(value: u16) -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
left: value,
|
|
|
|
horizontal: value,
|
|
|
|
right: value,
|
|
|
|
vertical: value,
|
|
|
|
top: value,
|
|
|
|
|
|
|
|
bottom: value,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Set the margin of left and right sides to specified value.
|
|
|
|
/// Set the margin of left and right sides to specified value.
|
|
|
|
pub fn horizontal(value: u16) -> Self {
|
|
|
|
pub const fn horizontal(value: u16) -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
left: value,
|
|
|
|
horizontal: value,
|
|
|
|
right: value,
|
|
|
|
vertical: 0,
|
|
|
|
top: 0,
|
|
|
|
|
|
|
|
bottom: 0,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Set the margin of top and bottom sides to specified value.
|
|
|
|
/// Set the margin of top and bottom sides to specified value.
|
|
|
|
pub fn vertical(value: u16) -> Self {
|
|
|
|
pub const fn vertical(value: u16) -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
left: 0,
|
|
|
|
horizontal: 0,
|
|
|
|
right: 0,
|
|
|
|
vertical: value,
|
|
|
|
top: value,
|
|
|
|
|
|
|
|
bottom: value,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Get the total width of the margin (left + right)
|
|
|
|
/// Get the total width of the margin (left + right)
|
|
|
|
pub fn width(&self) -> u16 {
|
|
|
|
pub const fn width(&self) -> u16 {
|
|
|
|
self.left + self.right
|
|
|
|
self.horizontal * 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Get the total height of the margin (top + bottom)
|
|
|
|
/// Get the total height of the margin (top + bottom)
|
|
|
|
pub fn height(&self) -> u16 {
|
|
|
|
pub const fn height(&self) -> u16 {
|
|
|
|
self.top + self.bottom
|
|
|
|
self.vertical * 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -181,13 +171,13 @@ impl Rect {
|
|
|
|
Self::new(self.x, self.y, width, self.height)
|
|
|
|
Self::new(self.x, self.y, width, self.height)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn inner(self, margin: &Margin) -> Rect {
|
|
|
|
pub fn inner(self, margin: Margin) -> Rect {
|
|
|
|
if self.width < margin.width() || self.height < margin.height() {
|
|
|
|
if self.width < margin.width() || self.height < margin.height() {
|
|
|
|
Rect::default()
|
|
|
|
Rect::default()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Rect {
|
|
|
|
Rect {
|
|
|
|
x: self.x + margin.left,
|
|
|
|
x: self.x + margin.horizontal,
|
|
|
|
y: self.y + margin.top,
|
|
|
|
y: self.y + margin.vertical,
|
|
|
|
width: self.width - margin.width(),
|
|
|
|
width: self.width - margin.width(),
|
|
|
|
height: self.height - margin.height(),
|
|
|
|
height: self.height - margin.height(),
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -459,7 +449,13 @@ pub struct Style {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for Style {
|
|
|
|
impl Default for Style {
|
|
|
|
fn default() -> Style {
|
|
|
|
fn default() -> Self {
|
|
|
|
|
|
|
|
Self::new()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Style {
|
|
|
|
|
|
|
|
pub const fn new() -> Self {
|
|
|
|
Style {
|
|
|
|
Style {
|
|
|
|
fg: None,
|
|
|
|
fg: None,
|
|
|
|
bg: None,
|
|
|
|
bg: None,
|
|
|
@ -469,12 +465,10 @@ impl Default for Style {
|
|
|
|
sub_modifier: Modifier::empty(),
|
|
|
|
sub_modifier: Modifier::empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Style {
|
|
|
|
|
|
|
|
/// Returns a `Style` resetting all properties.
|
|
|
|
/// Returns a `Style` resetting all properties.
|
|
|
|
pub fn reset() -> Style {
|
|
|
|
pub const fn reset() -> Self {
|
|
|
|
Style {
|
|
|
|
Self {
|
|
|
|
fg: Some(Color::Reset),
|
|
|
|
fg: Some(Color::Reset),
|
|
|
|
bg: Some(Color::Reset),
|
|
|
|
bg: Some(Color::Reset),
|
|
|
|
underline_color: None,
|
|
|
|
underline_color: None,
|
|
|
@ -494,7 +488,7 @@ impl Style {
|
|
|
|
/// let diff = Style::default().fg(Color::Red);
|
|
|
|
/// let diff = Style::default().fg(Color::Red);
|
|
|
|
/// assert_eq!(style.patch(diff), Style::default().fg(Color::Red));
|
|
|
|
/// assert_eq!(style.patch(diff), Style::default().fg(Color::Red));
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
pub fn fg(mut self, color: Color) -> Style {
|
|
|
|
pub const fn fg(mut self, color: Color) -> Style {
|
|
|
|
self.fg = Some(color);
|
|
|
|
self.fg = Some(color);
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -509,7 +503,7 @@ impl Style {
|
|
|
|
/// let diff = Style::default().bg(Color::Red);
|
|
|
|
/// let diff = Style::default().bg(Color::Red);
|
|
|
|
/// assert_eq!(style.patch(diff), Style::default().bg(Color::Red));
|
|
|
|
/// assert_eq!(style.patch(diff), Style::default().bg(Color::Red));
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
pub fn bg(mut self, color: Color) -> Style {
|
|
|
|
pub const fn bg(mut self, color: Color) -> Style {
|
|
|
|
self.bg = Some(color);
|
|
|
|
self.bg = Some(color);
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -524,7 +518,7 @@ impl Style {
|
|
|
|
/// let diff = Style::default().underline_color(Color::Red);
|
|
|
|
/// let diff = Style::default().underline_color(Color::Red);
|
|
|
|
/// assert_eq!(style.patch(diff), Style::default().underline_color(Color::Red));
|
|
|
|
/// assert_eq!(style.patch(diff), Style::default().underline_color(Color::Red));
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
pub fn underline_color(mut self, color: Color) -> Style {
|
|
|
|
pub const fn underline_color(mut self, color: Color) -> Style {
|
|
|
|
self.underline_color = Some(color);
|
|
|
|
self.underline_color = Some(color);
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -539,7 +533,7 @@ impl Style {
|
|
|
|
/// let diff = Style::default().underline_style(UnderlineStyle::Curl);
|
|
|
|
/// let diff = Style::default().underline_style(UnderlineStyle::Curl);
|
|
|
|
/// assert_eq!(style.patch(diff), Style::default().underline_style(UnderlineStyle::Curl));
|
|
|
|
/// assert_eq!(style.patch(diff), Style::default().underline_style(UnderlineStyle::Curl));
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
pub fn underline_style(mut self, style: UnderlineStyle) -> Style {
|
|
|
|
pub const fn underline_style(mut self, style: UnderlineStyle) -> Style {
|
|
|
|
self.underline_style = Some(style);
|
|
|
|
self.underline_style = Some(style);
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|