Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Calculate cell size
Browse files Browse the repository at this point in the history
  • Loading branch information
swsnr committed Apr 21, 2023
1 parent 57b4b10 commit a223c03
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pulldown-cmark-mdcat/src/terminal/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,16 @@ impl TerminalSize {
pub fn detect() -> Option<Self> {
Self::from_terminal().or_else(Self::from_env)
}

/// Get the size of a cell if known.
///
/// Calculates the cell size by dividing the pixel size by the rows and columns.
///
/// Return `None` if the pixel size is not known.
pub fn cell_size(&self) -> Option<PixelSize> {
self.pixels.map(|s| PixelSize {
x: s.x / self.columns as u32,
y: s.y / self.rows as u32,
})
}
}

0 comments on commit a223c03

Please sign in to comment.