From: notoria Date: Sat, 18 Apr 2020 11:54:18 +0000 (+0200) Subject: Removed $raw_input_read_char X-Git-Tag: v0.8.123~141 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=3f578e24b59e055b6c7ed25bcd38de3be1c8fb08;p=scryer-prolog.git Removed $raw_input_read_char --- diff --git a/src/prolog/clause_types.rs b/src/prolog/clause_types.rs index 37c8f612..660de341 100644 --- a/src/prolog/clause_types.rs +++ b/src/prolog/clause_types.rs @@ -242,7 +242,6 @@ pub enum SystemClauseType { InstallNewBlock, Maybe, QuotedToken, - RawInputReadChar, ReadTermFromChars, ResetBlock, ReturnFromVerifyAttr, @@ -366,7 +365,6 @@ impl SystemClauseType { &SystemClauseType::QuotedToken => { clause_name!("$quoted_token") } - &SystemClauseType::RawInputReadChar => clause_name!("$raw_input_read_char"), &SystemClauseType::RedoAttrVarBinding => clause_name!("$redo_attr_var_binding"), &SystemClauseType::RemoveCallPolicyCheck => clause_name!("$remove_call_policy_check"), &SystemClauseType::RemoveInferenceCounter => clause_name!("$remove_inference_counter"), @@ -509,7 +507,6 @@ impl SystemClauseType { ("$get_cp", 1) => Some(SystemClauseType::GetCutPoint), ("$install_new_block", 1) => Some(SystemClauseType::InstallNewBlock), ("$quoted_token", 1) => Some(SystemClauseType::QuotedToken), - ("$raw_input_read_char", 1) => Some(SystemClauseType::RawInputReadChar), ("$nextEP", 3) => Some(SystemClauseType::NextEP), ("$read_query_term", 2) => Some(SystemClauseType::ReadQueryTerm), ("$read_term", 2) => Some(SystemClauseType::ReadTerm), diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index 1a783ac9..e2cad96a 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -31,42 +31,6 @@ use std::rc::Rc; use crate::crossterm::event::{read, Event, KeyCode, KeyEvent}; use crate::crossterm::terminal::{enable_raw_mode, disable_raw_mode}; -pub enum ContinueResult { - ContinueQuery, - Conclude, - Help, - PrintWithoutMaxDepth, - PrintWithMaxDepth -} - -pub fn next_keypress() -> ContinueResult { - loop { - match read() { - Ok(Event::Key(KeyEvent { code, .. })) => { - match code { - KeyCode::Char('w') => { - return ContinueResult::PrintWithoutMaxDepth; - } - KeyCode::Char('p') => { - return ContinueResult::PrintWithMaxDepth; - } - KeyCode::Char(' ') | KeyCode::Char(';') | KeyCode::Char('n') => { - return ContinueResult::ContinueQuery; - } - KeyCode::Char('.') => { - return ContinueResult::Conclude; - } - KeyCode::Char('h') => { - return ContinueResult::Help; - } - _ => {} - } - } - _ => {} - } - } -} - pub fn get_single_char() -> char { let c; enable_raw_mode().expect("failed to enable raw mode"); @@ -2913,26 +2877,6 @@ impl MachineState { &SystemClauseType::InstallNewBlock => { self.install_new_block(temp_v!(1)); } - &SystemClauseType::RawInputReadChar => { - let keypress = { - enable_raw_mode().expect("failed to transition into raw mode"); - let result = next_keypress(); - disable_raw_mode().expect("failed to transition out of raw mode"); - - result - }; - - let c = match keypress { - ContinueResult::ContinueQuery => ';', - ContinueResult::Conclude => '.', - ContinueResult::Help => 'h', - ContinueResult::PrintWithoutMaxDepth => 'w', - ContinueResult::PrintWithMaxDepth => 'p', - }; - - let target = self[temp_v!(1)]; - self.unify(Addr::Char(c), target); - } &SystemClauseType::NextEP => { let first_arg = self.store(self.deref(self[temp_v!(1)])); diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index a3c3f1af..fbf180ad 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -146,7 +146,7 @@ ). '$read_input'(ThreadedGoals, NewVarList) :- - '$raw_input_read_char'(C), + '$get_single_char'(C), ( C == w -> nl, write(' '), @@ -162,8 +162,9 @@ ; C == h -> '$help_message', '$read_input'(ThreadedGoals, NewVarList) - ; C == '.', + ; C == '.' -> nl, write('; ...'), nl + ; '$read_input'(ThreadedGoals, NewVarList) ). '$help_message' :-