summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Porte <microjoe@microjoe.org>2020-02-23 10:30:17 +0100
committerRomain Porte <microjoe@microjoe.org>2020-02-23 10:30:17 +0100
commitcc06ec11a6824151ae07418956f3897ab19080ef (patch)
tree6c2209527ad51a4b6ae4367b1dba2a673a744fd2
parent9579f4cbfef9e53eefdadcd366e577d0514ff7ed (diff)
downloadcharlcd-cc06ec11a6824151ae07418956f3897ab19080ef.tar.gz
charlcd-cc06ec11a6824151ae07418956f3897ab19080ef.zip
add goto functions
-rw-r--r--src/codes.rs2
-rw-r--r--src/lib.rs12
2 files changed, 14 insertions, 0 deletions
diff --git a/src/codes.rs b/src/codes.rs
index 2111df7..e397df8 100644
--- a/src/codes.rs
+++ b/src/codes.rs
@@ -46,6 +46,7 @@ pub enum SpecialCode {
GotoXY(Option<u32>, Option<u32>),
}
+/// Write a X or Y goto symbol, as required
fn write_goto_xy_sym<T: Write>(writer: &mut T, sym: char, value: Option<u32>) -> Result<usize> {
let mut total = 0;
if let Some(value) = value {
@@ -55,6 +56,7 @@ fn write_goto_xy_sym<T: Write>(writer: &mut T, sym: char, value: Option<u32>) ->
Ok(total)
}
+/// Write both X and/or Y goto symbol, as required
fn write_goto_xy<T: Write>(writer: &mut T, x: Option<u32>, y: Option<u32>) -> Result<usize> {
let mut total = 0;
total += write_goto_xy_sym(writer, 'x', x)?;
diff --git a/src/lib.rs b/src/lib.rs
index 5679f60..b573b1a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -287,6 +287,18 @@ where
pub fn large_font(&mut self) -> std::io::Result<()> {
write_simple_code!(self, SpecialCode::LargeFont)
}
+
+ pub fn gotoxy(&mut self, x: u32, y: u32) -> std::io::Result<()> {
+ write_simple_code!(self, SpecialCode::GotoXY(Some(x), Some(y)))
+ }
+
+ pub fn gotox(&mut self, x: u32) -> std::io::Result<()> {
+ write_simple_code!(self, SpecialCode::GotoXY(Some(x), None))
+ }
+
+ pub fn gotoy(&mut self, y: u32) -> std::io::Result<()> {
+ write_simple_code!(self, SpecialCode::GotoXY(None, Some(y)))
+ }
}
// Reimplement Write trait for Screen, so that user can call the write and