aboutsummaryrefslogtreecommitdiffstats
path: root/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/types.rs b/src/types.rs
new file mode 100644
index 0000000..dd432eb
--- /dev/null
+++ b/src/types.rs
@@ -0,0 +1,50 @@
+/// Represents the size of the pty.
+#[derive(Debug, Clone, Copy)]
+pub struct Size {
+ row: u16,
+ col: u16,
+ xpixel: u16,
+ ypixel: u16,
+}
+
+impl Size {
+ /// Returns a [`Size`](Size) instance with the given number of rows and
+ /// columns.
+ #[must_use]
+ pub fn new(row: u16, col: u16) -> Self {
+ Self {
+ row,
+ col,
+ xpixel: 0,
+ ypixel: 0,
+ }
+ }
+
+ /// Returns a [`Size`](Size) instance with the given number of rows and
+ /// columns, as well as the given pixel dimensions.
+ #[must_use]
+ pub fn new_with_pixel(
+ row: u16,
+ col: u16,
+ xpixel: u16,
+ ypixel: u16,
+ ) -> Self {
+ Self {
+ row,
+ col,
+ xpixel,
+ ypixel,
+ }
+ }
+}
+
+impl From<Size> for nix::pty::Winsize {
+ fn from(size: Size) -> Self {
+ Self {
+ ws_row: size.row,
+ ws_col: size.col,
+ ws_xpixel: size.xpixel,
+ ws_ypixel: size.ypixel,
+ }
+ }
+}