Added predicate for reading a single character

This commit is contained in:
notoria
2020-04-18 11:49:28 +02:00
committed by Mark Thom
parent f96e694ff8
commit d3a1f11dfe
3 changed files with 37 additions and 2 deletions

View File

@@ -67,6 +67,24 @@ pub fn next_keypress() -> ContinueResult {
}
}
pub fn get_single_char() -> char {
let c;
enable_raw_mode().expect("failed to enable raw mode");
loop {
if let Ok(Event::Key(KeyEvent { code, .. })) = read() {
match code {
KeyCode::Char(ch) => {
c = ch;
break;
},
_ => ()
}
}
}
disable_raw_mode().expect("failed to disable raw mode");
c
}
struct BrentAlgState {
hare: Addr,
tortoise: Addr,
@@ -1463,6 +1481,13 @@ impl MachineState {
}
}
}
&SystemClauseType::GetSingleChar => {
let c = get_single_char();
let a1 = self[temp_v!(1)];
self.unify(Addr::Char(c), a1);
}
&SystemClauseType::GetModuleClause => {
let module = self[temp_v!(3)];
let head = self[temp_v!(1)];