diff options
Diffstat (limited to 'src/term.rs')
-rw-r--r-- | src/term.rs | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/term.rs b/src/term.rs index 33890ad5..d2d711b4 100644 --- a/src/term.rs +++ b/src/term.rs @@ -162,11 +162,12 @@ pub use self::cell::Cell; pub mod mode { bitflags! { pub flags TermMode: u8 { - const SHOW_CURSOR = 0b00000001, - const APP_CURSOR = 0b00000010, - const APP_KEYPAD = 0b00000100, - const ANY = 0b11111111, - const NONE = 0b00000000, + const SHOW_CURSOR = 0b00000001, + const APP_CURSOR = 0b00000010, + const APP_KEYPAD = 0b00000100, + const MOUSE_REPORT_CLICK = 0b00001000, + const ANY = 0b11111111, + const NONE = 0b00000000, } } @@ -288,6 +289,24 @@ impl Term { } } + /// Convert the given pixel values to a grid coordinate + /// + /// The mouse coordinates are expected to be relative to the top left. The + /// line and column returned are also relative to the top left. + /// + /// Returns None if the coordinates are outside the screen + pub fn pixels_to_coords(&self, x: usize, y: usize) -> Option<(Line, Column)> { + let size = self.size_info(); + if x > size.width as usize || y > size.height as usize { + return None; + } + + let col = Column(x / (size.cell_width as usize)); + let line = Line(y / (size.cell_height as usize)); + + Some((line, col)) + } + pub fn grid(&self) -> &Grid<Cell> { &self.grid } @@ -815,6 +834,7 @@ impl ansi::Handler for Term { ansi::Mode::SwapScreenAndSetRestoreCursor => self.swap_alt(), ansi::Mode::ShowCursor => self.mode.insert(mode::SHOW_CURSOR), ansi::Mode::CursorKeys => self.mode.insert(mode::APP_CURSOR), + ansi::Mode::ReportMouseClicks => self.mode.insert(mode::MOUSE_REPORT_CLICK), _ => { debug_println!(".. ignoring set_mode"); } @@ -828,6 +848,7 @@ impl ansi::Handler for Term { ansi::Mode::SwapScreenAndSetRestoreCursor => self.swap_alt(), ansi::Mode::ShowCursor => self.mode.remove(mode::SHOW_CURSOR), ansi::Mode::CursorKeys => self.mode.remove(mode::APP_CURSOR), + ansi::Mode::ReportMouseClicks => self.mode.remove(mode::MOUSE_REPORT_CLICK), _ => { debug_println!(".. ignoring unset_mode"); } |