aboutsummaryrefslogtreecommitdiff
path: root/src/term
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-12-11 22:02:03 -0800
committerJoe Wilm <joe@jwilm.com>2016-12-11 22:02:03 -0800
commit4b63bddd55853e878ec0f85b4613dd02749a3811 (patch)
tree02faaf58b29e3e8c5767bca1c2254376d2f47fb6 /src/term
parent79e02b0b2f2feb127ff1c7dc998d4696e005003a (diff)
downloadalacritty-4b63bddd55853e878ec0f85b4613dd02749a3811.tar.gz
alacritty-4b63bddd55853e878ec0f85b4613dd02749a3811.zip
Track terminal cells on mouse movement
The cell under the cursor is now tracked in the input processor at `self.mouse.line` and `self.mouse.column`. This could probably be optimized to only compute the cell when in certain states, but the calculation is cheap.
Diffstat (limited to 'src/term')
-rw-r--r--src/term/mod.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs
index da5683e0..523fcb62 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -259,6 +259,17 @@ impl SizeInfo {
pub fn cols(&self) -> Column {
Column((self.width / self.cell_width) as usize)
}
+
+ pub fn pixels_to_coords(&self, x: usize, y: usize) -> Option<(Line, Column)> {
+ if x > self.width as usize || y > self.height as usize {
+ return None;
+ }
+
+ let col = Column(x / (self.cell_width as usize));
+ let line = Line(y / (self.cell_height as usize));
+
+ Some((line, col))
+ }
}
impl Term {
@@ -306,15 +317,7 @@ impl Term {
///
/// 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))
+ self.size_info().pixels_to_coords(x, y)
}
/// Access to the raw grid data structure