1 use std::cmp::{Ord, Ordering, PartialOrd}; 2 3 #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] 4 pub struct Position { 5 pub col: usize, // The leftmost column is number 0. 6 pub row: usize, // The highest row is number 0. 7 } 8 9 impl PartialOrd for Position { 10 fn partial_cmp(&self, other: &Self) -> Option<Ordering> { 11 Some(self.cmp(other)) 12 } 13 } 14 15 impl Ord for Position { 16 fn cmp(&self, other: &Self) -> Ordering { 17 match self.row.cmp(&other.row) { 18 Ordering::Equal => self.col.cmp(&other.col), 19 o => o, 20 } 21 } 22 } 23 24 #[derive(Debug, Default)] 25 pub struct Layout { 26 /// Prompt Unicode/visible width and height 27 pub prompt_size: Position, 28 pub default_prompt: bool, 29 /// Cursor position (relative to the start of the prompt) 30 pub cursor: Position, 31 /// Number of rows used so far (from start of prompt to end of input) 32 pub end: Position, 33 } 34