From 7ff11dce35e16e732db3ebb8758be19e941b89dc Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sun, 15 Mar 2020 13:16:40 +0100 Subject: [PATCH 1/2] support 'p' to reprint answer with max depth, allowing w -> p -> w ... --- src/prolog/machine/system_calls.rs | 5 +++++ src/prolog/toplevel.pl | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index 2b521d40..9e426227 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -34,6 +34,7 @@ pub enum ContinueResult { ContinueQuery, Conclude, PrintWithoutMaxDepth, + PrintWithMaxDepth } pub fn next_keypress() -> ContinueResult { @@ -44,6 +45,9 @@ pub fn next_keypress() -> ContinueResult { KeyCode::Char('w') => { return ContinueResult::PrintWithoutMaxDepth; } + KeyCode::Char('p') => { + return ContinueResult::PrintWithMaxDepth; + } KeyCode::Char(' ') | KeyCode::Char(';') | KeyCode::Char('n') => { return ContinueResult::ContinueQuery; } @@ -2348,6 +2352,7 @@ impl MachineState { ContinueResult::ContinueQuery => ';', ContinueResult::Conclude => '.', ContinueResult::PrintWithoutMaxDepth => 'w', + ContinueResult::PrintWithMaxDepth => 'p', }; let target = self[temp_v!(1)].clone(); diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index edf00883..be7b255a 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -184,14 +184,19 @@ '$read_input'(ThreadedGoals, NewVarList) :- '$raw_input_read_char'(C), - ( C == ('w'), !, + ( C == w -> nl, write(' '), '$write_eq'(ThreadedGoals, NewVarList, 0), '$read_input'(ThreadedGoals, NewVarList) - ; C == (';'), !, + ; C == p -> + nl, + write(' '), + '$write_eq'(ThreadedGoals, NewVarList, 20), + '$read_input'(ThreadedGoals, NewVarList) + ; C == (';') -> nl, write('; '), false - ; C == ('.'), !, + ; C == '.', nl, write(' ...'), nl ). From 17a448e0452cbd4121903fdb9f75b67b320daf86 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sun, 15 Mar 2020 13:24:28 +0100 Subject: [PATCH 2/2] support 'h' to print help message during toplevel interaction --- src/prolog/machine/system_calls.rs | 5 +++++ src/prolog/toplevel.pl | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index 9e426227..03ec8311 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -33,6 +33,7 @@ use crate::crossterm::terminal::{enable_raw_mode, disable_raw_mode}; pub enum ContinueResult { ContinueQuery, Conclude, + Help, PrintWithoutMaxDepth, PrintWithMaxDepth } @@ -54,6 +55,9 @@ pub fn next_keypress() -> ContinueResult { KeyCode::Char('.') => { return ContinueResult::Conclude; } + KeyCode::Char('h') => { + return ContinueResult::Help; + } _ => {} } } @@ -2351,6 +2355,7 @@ impl MachineState { let c = match keypress { ContinueResult::ContinueQuery => ';', ContinueResult::Conclude => '.', + ContinueResult::Help => 'h', ContinueResult::PrintWithoutMaxDepth => 'w', ContinueResult::PrintWithMaxDepth => 'p', }; diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index be7b255a..3abadd7c 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -196,10 +196,21 @@ '$read_input'(ThreadedGoals, NewVarList) ; C == (';') -> nl, write('; '), false + ; C == h -> + '$help_message', + '$read_input'(ThreadedGoals, NewVarList) ; C == '.', nl, write(' ...'), nl ). +'$help_message' :- + nl, nl, + write('SPACE, "n" or ";": next solution, if any\n'), + write('".": stop enumeration\n'), + write('"h": display this help message\n'), + write('"w": write terms without depth limit\n'), + write('"p": print terms with depth limit\n\n'). + '$gather_query_vars'([_ = Var | Vars], QueryVars) :- ( var(Var) -> QueryVars = [Var | QueryVars1],