aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2017-01-06 15:48:23 -0800
committerManish Goregaokar <manishsmail@gmail.com>2017-01-06 20:17:10 -0800
commitc579d079939b5d4ee3127579de732f037e612c28 (patch)
treec5494720937e0c531c305663823761b137289a31
parentee5a9f133869809385bef96fcded4f22ddcc003f (diff)
downloadalacritty-c579d079939b5d4ee3127579de732f037e612c28.tar.gz
alacritty-c579d079939b5d4ee3127579de732f037e612c28.zip
Remove need for range_contains feature
-rw-r--r--src/ansi.rs4
-rw-r--r--src/index.rs25
-rw-r--r--src/lib.rs1
-rw-r--r--src/term/mod.rs8
4 files changed, 30 insertions, 8 deletions
diff --git a/src/ansi.rs b/src/ansi.rs
index e5c129e3..345e4e64 100644
--- a/src/ansi.rs
+++ b/src/ansi.rs
@@ -18,7 +18,7 @@ use std::io;
use vte;
-use index::{Column, Line};
+use index::{Column, Line, Contains};
use ::Rgb;
@@ -744,7 +744,7 @@ fn parse_color(attrs: &[i64], i: &mut usize) -> Option<Color> {
*i += 4;
let range = 0...255;
- if !range.contains(r) || !range.contains(g) || !range.contains(b) {
+ if !range.contains_(r) || !range.contains_(g) || !range.contains_(b) {
err_println!("Invalid RGB color spec: ({}, {}, {})", r, g, b);
return None;
}
diff --git a/src/index.rs b/src/index.rs
index b1f6f452..daec02f7 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -17,7 +17,7 @@
/// Indexing types and implementations for Grid and Line
use std::cmp::{Ord, Ordering};
use std::fmt;
-use std::ops::{self, Deref, Add, Range};
+use std::ops::{self, Deref, Add, Range, RangeInclusive};
/// The side of a cell
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
@@ -210,6 +210,29 @@ impl<T> From<Range<T>> for IndexRange<T> {
}
}
+// can be removed if range_contains is stabilized
+
+pub trait Contains {
+ type Content;
+ fn contains_(&self, item: Self::Content) -> bool;
+}
+
+impl<T: PartialOrd<T>> Contains for Range<T> {
+ type Content = T;
+ fn contains_(&self, item: Self::Content) -> bool {
+ (self.start <= item) && (item < self.end)
+ }
+}
+
+impl<T: PartialOrd<T>> Contains for RangeInclusive<T> {
+ type Content = T;
+ fn contains_(&self, item: Self::Content) -> bool {
+ if let &RangeInclusive::NonEmpty{ref start, ref end} = self {
+ (*start <= item) && (item <= *end)
+ } else { false }
+ }
+}
+
macro_rules! ops {
($ty:ty, $construct:expr) => {
add!($ty, $construct);
diff --git a/src/lib.rs b/src/lib.rs
index 46e9dceb..730f165a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,7 +13,6 @@
// limitations under the License.
//
//! Alacritty - The GPU Enhanced Terminal
-#![feature(range_contains)]
#![feature(inclusive_range_syntax)]
#![feature(inclusive_range)]
#![cfg_attr(feature = "clippy", feature(plugin))]
diff --git a/src/term/mod.rs b/src/term/mod.rs
index 4c2afc35..975ba376 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -20,7 +20,7 @@ use std::io;
use ansi::{self, Color, NamedColor, Attr, Handler};
use grid::{Grid, ClearRegion, ToRange};
-use index::{self, Point, Column, Line, Linear, IndexRange};
+use index::{self, Point, Column, Line, Linear, IndexRange, Contains};
use selection::{Span, Selection};
pub mod cell;
@@ -129,7 +129,7 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
self.column += 1;
let selected = self.selection.as_ref()
- .map(|range| range.contains(index))
+ .map(|range| range.contains_(index))
.unwrap_or(false);
// Skip empty cells
@@ -812,7 +812,7 @@ impl ansi::Handler for Term {
#[inline]
fn insert_blank_lines(&mut self, lines: Line) {
debug_println!("insert_blank_lines: {}", lines);
- if self.scroll_region.contains(self.cursor.line) {
+ if self.scroll_region.contains_(self.cursor.line) {
let origin = self.cursor.line;
self.scroll_down_relative(origin, lines);
}
@@ -821,7 +821,7 @@ impl ansi::Handler for Term {
#[inline]
fn delete_lines(&mut self, lines: Line) {
debug_println!("delete_lines: {}", lines);
- if self.scroll_region.contains(self.cursor.line) {
+ if self.scroll_region.contains_(self.cursor.line) {
let origin = self.cursor.line;
self.scroll_up_relative(origin, lines);
}