Skip to content

Commit

Permalink
Add loop event in normal state
Browse files Browse the repository at this point in the history
  • Loading branch information
Mroik committed May 7, 2024
1 parent 9be1a80 commit 0837c76
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ struct App {

impl App {
fn new() -> std::io::Result<App> {

Check warning on line 13 in src/app.rs

View workflow job for this annotation

GitHub Actions / tests

associated items `new`, `render`, `listen`, `listen_normal`, and `info_text` are never used
Ok(App {
let mut app = App {
model: Fitch::new(),
renderer: Renderer::new()?,
state: State::Noraml,
expression_buffer: String::new(),
})
};
app.render();
Ok(app)
}

fn render(&mut self) {
Expand All @@ -29,14 +31,33 @@ impl App {

fn listen(&mut self) {
loop {
if self.state == State::Quit {
break;
}

if let Event::Key(key) = event::read().unwrap() {
if key.kind != KeyEventKind::Press {
continue;
}
match key.code {

match self.state {
State::Noraml => self.listen_normal(&key.code),
_ => todo!(),
}
}

self.render();
}
}

fn listen_normal(&mut self, code: &KeyCode) {
match code {
KeyCode::Char('i') => self.state = State::IntroduceChoice,
KeyCode::Char('e') => self.state = State::EliminateChoice,
KeyCode::Char('a') => self.state = State::AddAssumption,
KeyCode::Char('s') => self.state = State::AddSubproof,
KeyCode::Char('q') => self.state = State::Quit,
_ => (),
}
}

Expand All @@ -48,6 +69,7 @@ impl App {
"add [a]ssumption",
"add [s]ubproof",
"[d]elete last row",
"[q]uit",
]
.join(" ")
.to_string(),
Expand All @@ -56,28 +78,37 @@ impl App {
}
}

#[derive(PartialEq)]
enum State {

Check warning on line 82 in src/app.rs

View workflow job for this annotation

GitHub Actions / tests

enum `State` is never used
Noraml,
IntroduceChoice,
EliminateChoice,
AddAssumption,
AddSubproof,
AbsurdumState(AbsurdumState),
AndState(AndState),
OrState(OrState),
NotState(NotState),
ImpliesState(ImpliesState),
IffState(IffState),
Quit,
}

#[derive(PartialEq)]
enum AbsurdumState {

Check warning on line 98 in src/app.rs

View workflow job for this annotation

GitHub Actions / tests

enum `AbsurdumState` is never used
IntroduceGetAssumption1,
IntroduceGetAssumption2(usize),
}

#[derive(PartialEq)]
enum AndState {

Check warning on line 104 in src/app.rs

View workflow job for this annotation

GitHub Actions / tests

enum `AndState` is never used
IntroduceGetLeftAssumption,
IntroduceGetRightAssumption(usize),
EliminateGetAssumption,
EliminateGetProposition(usize),
}

#[derive(PartialEq)]
enum OrState {

Check warning on line 112 in src/app.rs

View workflow job for this annotation

GitHub Actions / tests

enum `OrState` is never used
IntroduceGetAssumption,
IntroduceGetProposition(usize),
Expand All @@ -86,17 +117,20 @@ enum OrState {
EliminateGetRightSubproof(usize, usize),
}

#[derive(PartialEq)]
enum NotState {

Check warning on line 121 in src/app.rs

View workflow job for this annotation

GitHub Actions / tests

enum `NotState` is never used
Introduce,
Eliminate,
}

#[derive(PartialEq)]
enum ImpliesState {

Check warning on line 127 in src/app.rs

View workflow job for this annotation

GitHub Actions / tests

enum `ImpliesState` is never used
Introduce,
EliminateGetAssumption,
EliminateGetLeft(usize),
}

#[derive(PartialEq)]
enum IffState {

Check warning on line 134 in src/app.rs

View workflow job for this annotation

GitHub Actions / tests

enum `IffState` is never used
IntroduceGetLeftSubproof,
IntroduceGetRightSubproof(usize),
Expand Down

0 comments on commit 0837c76

Please sign in to comment.