Skip to content

Commit

Permalink
feat(layout): impl Display for Position and Size (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka authored Jun 4, 2024
1 parent 2a74f9d commit 1520ed9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/layout/position.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![warn(missing_docs)]
use std::fmt;

use crate::layout::Rect;

/// Position in the terminal
Expand Down Expand Up @@ -61,6 +63,12 @@ impl From<Rect> for Position {
}
}

impl fmt::Display for Position {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -94,4 +102,10 @@ mod tests {
assert_eq!(position.x, 1);
assert_eq!(position.y, 2);
}

#[test]
fn to_string() {
let position = Position::new(1, 2);
assert_eq!(position.to_string(), "(1, 2)");
}
}
13 changes: 13 additions & 0 deletions src/layout/size.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![warn(missing_docs)]
use std::fmt;

use crate::prelude::*;

/// A simple size struct
Expand Down Expand Up @@ -32,6 +34,12 @@ impl From<Rect> for Size {
}
}

impl fmt::Display for Size {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}x{}", self.width, self.height)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -56,4 +64,9 @@ mod tests {
assert_eq!(size.width, 10);
assert_eq!(size.height, 20);
}

#[test]
fn display() {
assert_eq!(Size::new(10, 20).to_string(), "10x20");
}
}

0 comments on commit 1520ed9

Please sign in to comment.