Skip to content

Commit

Permalink
cleanup warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SamLee514 committed Aug 23, 2021
1 parent 6c8521d commit 7808c6f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
9 changes: 2 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
mod help;
mod runner;
mod writer;

use std::io::{self, Read, Stdout, Write};
use std::{
thread,
time::{Duration, Instant},
};
use std::io::{self, Stdout, Write};
use std::time::{Duration, Instant};
use structopt::StructOpt;
use termion::input::TermRead;
use termion::raw::{IntoRawMode, RawTerminal};
use termion::{self, async_stdin, event::Key, input::Keys, AsyncReader};
use termion::{clear, cursor};

#[derive(Debug, StructOpt)]
#[structopt(name = "morsel", about = "morse code CLI tool")]
Expand Down
31 changes: 13 additions & 18 deletions src/writer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
pub mod tree;

use std::io::{self, Error, Read, Write};
use std::io::{self, Error, ErrorKind, Write};
use termion::clear;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use termion::{self, cursor, event::Key, style};
use termion::{self, cursor, style};

pub struct Writer<W: Write> {
stdout: W,
Expand All @@ -15,59 +13,59 @@ pub struct Writer<W: Write> {
impl<W: Write> Writer<W> {
pub fn new(stdout: W) -> Self {
Self {
stdout: stdout,
stdout,
tree: tree::Tree::new(),
input_count: 0,
}
}

fn buffered_write(&mut self, content: &str) -> Result<(), std::io::Error> {
fn buffered_write(&mut self, content: &str) -> Result<(), Error> {
write!(self.stdout, "{}", content)?;
io::stdout().flush()?;
Ok(())
}

pub fn wipe(&mut self) -> Result<(), std::io::Error> {
pub fn wipe(&mut self) -> Result<(), Error> {
self.backspace(self.input_count)
}

pub fn backspace(&mut self, count: u16) -> Result<(), std::io::Error> {
pub fn backspace(&mut self, count: u16) -> Result<(), Error> {
write!(self.stdout, "{}", cursor::Left(count))?;
write!(self.stdout, "{}", clear::AfterCursor)?;
io::stdout().flush()?;
Ok(())
}

pub fn lockout(&mut self) -> Result<(), std::io::Error> {
pub fn lockout(&mut self) -> Result<(), Error> {
self.buffered_write(&style::Faint.to_string())?;
self.buffered_write(&cursor::Hide.to_string())?;
Ok(())
}

pub fn unlock(&mut self) -> Result<(), std::io::Error> {
pub fn unlock(&mut self) -> Result<(), Error> {
self.buffered_write(&cursor::Left(1).to_string())?;
self.buffered_write(&clear::AfterCursor.to_string())?;
self.buffered_write(&style::NoFaint.to_string())?;
self.buffered_write(&cursor::Show.to_string())?;
Ok(())
}

pub fn preview_dit(&mut self) -> Result<(), std::io::Error> {
pub fn preview_dit(&mut self) -> Result<(), Error> {
self.buffered_write(".")
}

pub fn preview_dah(&mut self) -> Result<(), std::io::Error> {
pub fn preview_dah(&mut self) -> Result<(), Error> {
self.buffered_write(&cursor::Left(1).to_string())?;
self.buffered_write(&clear::AfterCursor.to_string())?;
self.buffered_write("_")?;
Ok(())
}

pub fn end_word(&mut self) -> Result<(), std::io::Error> {
pub fn end_word(&mut self) -> Result<(), Error> {
self.buffered_write(" ")
}

pub fn process_input(&mut self, input: tree::Input) -> Result<(), std::io::Error> {
pub fn process_input(&mut self, input: tree::Input) -> Result<(), Error> {
match self.tree.traverse(input) {
tree::Output::Value(v) => {
self.wipe()?;
Expand All @@ -84,10 +82,7 @@ impl<W: Write> Writer<W> {
}
tree::Input::Space => {
self.wipe()?;
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Unexpected space",
));
return Err(Error::new(ErrorKind::InvalidInput, "Unexpected space"));
}
};
}
Expand Down
8 changes: 0 additions & 8 deletions src/writer/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ pub enum Output {
Oopsie,
}

// Need a character, a "pass" or an error
// Dits and Dahs don't try to access the character, so they are either "pass" or Error
// Space try to access the character, so they are either character or Error

struct Node<'a> {
left: Option<&'a str>,
right: Option<&'a str>,
Expand Down Expand Up @@ -408,7 +404,3 @@ impl Tree<'_> {
}
}
}

// Build the tree as an array
// Rest of the app passes in an array of dits and dahs, expects either a letter or an error
// Error signals to kill the currently-being-typed letter

0 comments on commit 7808c6f

Please sign in to comment.