aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs18
-rw-r--r--src/event.rs5
-rw-r--r--src/input.rs8
-rw-r--r--src/main.rs8
-rw-r--r--src/util.rs14
5 files changed, 30 insertions, 23 deletions
diff --git a/src/config.rs b/src/config.rs
index 30bbf1b5..3c4d25c6 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -72,7 +72,7 @@ impl ::std::fmt::Display for Error {
write!(f, "could not read $HOME environment variable: {}", err)
},
Error::Io(ref err) => write!(f, "error reading config file: {}", err),
- Error::Yaml(ref err) => write!(f, "problem with config: {}", err),
+ Error::Yaml(ref err) => write!(f, "problem with config: {:?}", err),
}
}
}
@@ -240,26 +240,18 @@ impl DeserializeFromF32 for Size {
impl<__D> ::serde::de::Visitor for FloatVisitor<__D>
where __D: ::serde::de::Deserializer
{
- type Value = f32;
+ type Value = f64;
- fn visit_f32<E>(&mut self, value: f32) -> ::std::result::Result<Self::Value, E>
+ fn visit_f64<E>(&mut self, value: f64) -> ::std::result::Result<Self::Value, E>
where E: ::serde::de::Error
{
Ok(value)
}
-
- fn visit_str<E>(&mut self, value: &str) -> ::std::result::Result<Self::Value, E>
- where E: ::serde::de::Error
- {
- // FIXME serde-yaml visits a str for real numbers.
- // https://github.com/dtolnay/serde-yaml/issues/24
- Ok(value.parse::<f32>().expect("size must be float"))
- }
}
deserializer
- .deserialize_f32(FloatVisitor::<D>{ _marker: PhantomData })
- .map(|v| Size::new(v))
+ .deserialize_f64(FloatVisitor::<D>{ _marker: PhantomData })
+ .map(|v| Size::new(v as _))
}
}
diff --git a/src/event.rs b/src/event.rs
index cb99999a..dcaedc97 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -6,6 +6,7 @@ use glutin;
use input;
use sync::FairMutex;
use term::Term;
+use util::encode_char;
/// The event processor
pub struct Processor<N> {
@@ -45,8 +46,8 @@ impl<N: input::Notify> Processor<N> {
// These letters are handled in the bindings system
'v' => (),
_ => {
- let encoded = c.encode_utf8();
- self.notifier.notify(encoded.as_slice().to_vec());
+ let buf = encode_char(c);
+ self.notifier.notify(buf);
}
}
},
diff --git a/src/input.rs b/src/input.rs
index f1022814..6fb722d0 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -31,6 +31,7 @@ use glutin::{Mods, mods};
use term::mode::{self, TermMode};
use event_loop;
+use util::encode_char;
/// Processes input from glutin.
///
@@ -362,12 +363,7 @@ impl Processor {
println!("ok");
},
Action::Char(c) => {
- // TODO encode_utf8 returns an iterator with "as_slice"
- // https://github.com/rust-lang/rust/issues/27784 has some
- // discussion about this API changing to `write_utf8` which
- // requires passing a &mut [u8] to be written into.
- let encoded = c.encode_utf8();
- notifier.notify(encoded.as_slice().to_vec());
+ notifier.notify(encode_char(c));
}
}
diff --git a/src/main.rs b/src/main.rs
index acf47302..afc60a66 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,9 +19,13 @@
#![feature(drop_types_in_const)]
#![feature(unicode)]
#![feature(step_trait)]
-#![feature(custom_derive, plugin)]
-#![plugin(serde_macros)]
#![feature(core_intrinsics)]
+#![allow(stable_features)] // lying about question_mark because 1.14.0 isn't released!
+
+#![feature(proc_macro)]
+
+#[macro_use]
+extern crate serde_derive;
extern crate cgmath;
extern crate copypasta;
diff --git a/src/util.rs b/src/util.rs
index 69715d8e..eddb2a5a 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -27,3 +27,17 @@ pub mod thread {
pub use ::std::thread::*;
}
+pub fn encode_char(c: char) -> Vec<u8> {
+ let mut buf = Vec::with_capacity(4);
+ unsafe {
+ buf.set_len(4);
+ let len = {
+ let s = c.encode_utf8(&mut buf[..]);
+ s.len()
+ };
+ buf.set_len(len);
+ }
+
+ buf
+}
+