Commit d2920859 authored by Paul Woolcock's avatar Paul Woolcock

some small cleanup

parent eb05261e
Pipeline #59106548 passed with stage
in 2 minutes and 30 seconds
......@@ -59,7 +59,6 @@ impl Handler<Wrapper> for Action {
type Result = Result<(), Error>;
fn handle(&mut self, msg: Wrapper, _ctx: &mut Context<Self>) -> Self::Result {
self.logger.log(format!("got wrapper {:?}", msg));
let request = parse_post(msg.into(), &self.logger)?;
self.logger.log(format!("parsed input is {:?}", request));
match request {
......@@ -138,10 +137,9 @@ mod message {
}
}
fn parse_post(s: String, logger: &logger::Channel) -> Result<message::Request, Error> {
fn parse_post(s: String, _: &logger::Channel) -> Result<message::Request, Error> {
let s = s.trim();
if s.starts_with('(') {
logger.log("starts with '(', posting with CW");
let mut parts = s[1..].splitn(2, ')');
let cw = parts
.next()
......@@ -149,19 +147,16 @@ fn parse_post(s: String, logger: &logger::Channel) -> Result<message::Request, E
let content = parts.next().ok_or_else(|| Error::custom("no content"))?;
Ok(message::Request::PostWithCw(content.to_string(), cw.to_string()))
} else if s.starts_with('/') {
logger.log("starts with '/', parsing command");
let mut parts = s.splitn(2, ' ');
let cmd = parts
.next()
.ok_or_else(|| Error::custom("error parsing command"))?
.trim();
let cmd = cmd.to_lowercase();
logger.log(format!("cmd is {}", &cmd));
let content = parts
.next()
.unwrap_or_else(|| "")
.trim();
logger.log(format!("content is '{}'", &content));
match cmd.as_ref() {
"/fav" | "/f" => Ok(message::Request::Fav(content.to_string())),
"/showmore" | "/sm" => Ok(message::Request::ShowMore(content.to_string())),
......
......@@ -55,84 +55,3 @@ impl Handler<Start> for Input {
#[derive(Message)]
struct Start;
/*
*/
/*
use crossbeam::{channel, Receiver, RecvError};
use std::{io, thread, time::Duration};
pub enum Event<I> {
Input(I),
Tick,
}
/// A small event handler that wrap termion input and tick events. Each event
/// type is handled in its own thread and returned to a common `Receiver`
#[allow(dead_code)]
pub struct Events {
rx: Receiver<Event<Key>>,
input_handle: thread::JoinHandle<()>,
tick_handle: thread::JoinHandle<()>,
}
#[derive(Debug, Clone, Copy)]
pub struct Config {
pub tick_rate: Duration,
}
impl Default for Config {
fn default() -> Config {
Config {
tick_rate: Duration::from_millis(250),
}
}
}
impl Events {
pub fn new() -> Events {
Events::with_config(Config::default())
}
pub fn with_config(config: Config) -> Events {
let (tx, rx) = channel::unbounded();
let input_handle = {
let tx = tx.clone();
thread::spawn(move || {
let stdin = io::stdin();
for evt in stdin.keys() {
match evt {
Ok(key) => {
if let Err(_) = tx.send(Event::Input(key)) {
return;
}
}
Err(_) => {}
}
}
})
};
let tick_handle = {
let tx = tx.clone();
thread::spawn(move || {
let tx = tx.clone();
loop {
tx.send(Event::Tick).unwrap();
thread::sleep(config.tick_rate);
}
})
};
Events {
rx,
input_handle,
tick_handle,
}
}
pub fn next(&self) -> Result<Event<Key>, RecvError> {
self.rx.recv()
}
}
*/
......@@ -86,7 +86,7 @@ fn main() -> Result<()> {
let stdout = AlternateScreen::from(stdout);
let backend = TermionBackend::new(stdout);
let terminal = Terminal::new(backend).context(IoError)?;
System::run(|| {
Ok(System::run(|| {
let streaming_arbiter = Arbiter::new();
let ui_arbiter = Arbiter::new();
let input_arbiter = Arbiter::new();
......@@ -131,31 +131,5 @@ fn main() -> Result<()> {
)
});
})
.context(IoError)?;
/*
let (input_tx, input_rx) = channel::unbounded();
let (quit_tx, quit_rx) = channel::unbounded();
vec![
thread::spawn(move || {
logger.listen().expect("Logger thread panicked");
}),
thread::spawn(move || {
repo.listen().expect("Repo thread panicked");
}),
thread::spawn(move || {
client.listen().expect("Client thread panicked");
}),
thread::spawn(move || {
ui::run(input_tx, repo0, logger0).unwrap();
}),
thread::spawn(move || {
streaming::run(repo1, client0).unwrap();
}),
thread::spawn(move || {
action::run(input_rx, quit_tx, repo2, client1).unwrap();
}),
];
quit_rx.recv()?;
*/
Ok(())
.context(IoError)?)
}
......@@ -23,16 +23,16 @@ pub enum Error {
ActionError { source: action::Error },
}
type Term = Terminal<TermionBackend<AlternateScreen<RawTerminal<io::Stdout>>>>;
pub struct Ui {
input: String,
terminal: Terminal<TermionBackend<AlternateScreen<RawTerminal<io::Stdout>>>>,
terminal: Term,
repo: repo::Channel,
logger: logger::Channel,
action: action::Channel,
}
type Term = Terminal<TermionBackend<AlternateScreen<RawTerminal<io::Stdout>>>>;
impl Ui {
pub fn new(terminal: Term, repo: Addr<repo::Repo>, logger: logger::Channel, action: action::Channel) -> Ui {
Ui {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment