From 2f0c72e1e40b72ae2ac96a37201d8736fc9be8e7 Mon Sep 17 00:00:00 2001 From: Ticki Date: Mon, 7 Mar 2016 16:23:05 +0100 Subject: [PATCH] Remove warnings from example --- examples/simple.rs | 18 ++++++++++-------- src/control.rs | 11 +++++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/examples/simple.rs b/examples/simple.rs index b446ba7..61545a2 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -4,14 +4,15 @@ use libterm::{TermControl, raw_mode}; use std::io::{Read, Write, stdout, stdin}; fn main() { - let raw = raw_mode(); + let _raw = raw_mode(); let mut stdout = stdout(); - let mut stdin = stdin(); + let stdin = stdin(); - stdout.goto(5, 5); - stdout.clear(); - stdout.write(b"yo, 'q' will exit."); - stdout.flush(); + stdout.goto(5, 5).unwrap(); + stdout.clear().unwrap(); + stdout.write(b"yo, 'q' will exit.").unwrap(); + stdout.flush().unwrap(); + stdout.goto(20, 10).unwrap(); let mut bytes = stdin.bytes(); loop { @@ -20,9 +21,10 @@ fn main() { match b { b'q' => return, b'c' => stdout.clear(), + b'r' => stdout.rendition(91), a => stdout.write(&[a]), - }; + }.unwrap(); - stdout.flush(); + stdout.flush().unwrap(); } } diff --git a/src/control.rs b/src/control.rs index f0a2a2c..88e1fe1 100644 --- a/src/control.rs +++ b/src/control.rs @@ -27,12 +27,19 @@ pub trait TermControl { /// Go to a given position. fn goto(&mut self, x: u16, y: u16) -> IoResult { self.csi(&[ - (x / 10000 % 10) as u8, (x / 1000 % 10) as u8, (x / 100 % 10) as u8, (x / 10 % 10) as u8, (x % 10) as u8, + (x / 10000) as u8 + b'0', ((x / 1000) % 10) as u8 + b'0', ((x / 100) % 10) as u8 + b'0', ((x / 10) % 10) as u8 + b'0', (x % 10) as u8 + b'0', b';', - (y / 10000 % 10) as u8, (y / 1000 % 10) as u8, (y / 100 % 10) as u8, (y / 10 % 10) as u8, (y % 10) as u8, + (y / 10000) as u8 + b'0', ((y / 1000) % 10) as u8 + b'0', ((y / 100) % 10) as u8 + b'0', ((y / 10) % 10) as u8 + b'0', (y % 10) as u8 + b'0', b'H', ]) } + /// Set graphic rendition. + fn rendition(&mut self, r: u8) -> IoResult { + self.csi(&[ + r / 100 + b'0', r / 10 % 10 + b'0', r % 10 + b'0', + b'm', + ]) + } } impl TermControl for W {