beamterm_core/
position.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub struct CursorPosition {
4 pub col: u16,
6 pub row: u16,
8}
9
10impl CursorPosition {
11 #[must_use]
13 pub fn new(col: u16, row: u16) -> Self {
14 Self { col, row }
15 }
16
17 pub(crate) fn move_left(self, distance: u16) -> Option<CursorPosition> {
18 self.col
19 .checked_sub(distance)
20 .map(|col| CursorPosition::new(col, self.row))
21 }
22
23 pub(crate) fn move_right(self, distance: u16, row_length: u16) -> Option<CursorPosition> {
24 self.col
25 .checked_add(distance)
26 .map(|col| CursorPosition::new(col, self.row))
27 .filter(|&pos| pos.col < row_length)
28 }
29}