Merge pull request #291 from triska/toplevel

Two small toplevel features
This commit is contained in:
Mark Thom
2020-03-15 12:09:25 -03:00
committed by GitHub
2 changed files with 29 additions and 3 deletions

View File

@@ -33,7 +33,9 @@ use crate::crossterm::terminal::{enable_raw_mode, disable_raw_mode};
pub enum ContinueResult { pub enum ContinueResult {
ContinueQuery, ContinueQuery,
Conclude, Conclude,
Help,
PrintWithoutMaxDepth, PrintWithoutMaxDepth,
PrintWithMaxDepth
} }
pub fn next_keypress() -> ContinueResult { pub fn next_keypress() -> ContinueResult {
@@ -44,12 +46,18 @@ pub fn next_keypress() -> ContinueResult {
KeyCode::Char('w') => { KeyCode::Char('w') => {
return ContinueResult::PrintWithoutMaxDepth; return ContinueResult::PrintWithoutMaxDepth;
} }
KeyCode::Char('p') => {
return ContinueResult::PrintWithMaxDepth;
}
KeyCode::Char(' ') | KeyCode::Char(';') | KeyCode::Char('n') => { KeyCode::Char(' ') | KeyCode::Char(';') | KeyCode::Char('n') => {
return ContinueResult::ContinueQuery; return ContinueResult::ContinueQuery;
} }
KeyCode::Char('.') => { KeyCode::Char('.') => {
return ContinueResult::Conclude; return ContinueResult::Conclude;
} }
KeyCode::Char('h') => {
return ContinueResult::Help;
}
_ => {} _ => {}
} }
} }
@@ -2347,7 +2355,9 @@ impl MachineState {
let c = match keypress { let c = match keypress {
ContinueResult::ContinueQuery => ';', ContinueResult::ContinueQuery => ';',
ContinueResult::Conclude => '.', ContinueResult::Conclude => '.',
ContinueResult::Help => 'h',
ContinueResult::PrintWithoutMaxDepth => 'w', ContinueResult::PrintWithoutMaxDepth => 'w',
ContinueResult::PrintWithMaxDepth => 'p',
}; };
let target = self[temp_v!(1)].clone(); let target = self[temp_v!(1)].clone();

View File

@@ -184,17 +184,33 @@
'$read_input'(ThreadedGoals, NewVarList) :- '$read_input'(ThreadedGoals, NewVarList) :-
'$raw_input_read_char'(C), '$raw_input_read_char'(C),
( C == ('w'), !, ( C == w ->
nl, nl,
write(' '), write(' '),
'$write_eq'(ThreadedGoals, NewVarList, 0), '$write_eq'(ThreadedGoals, NewVarList, 0),
'$read_input'(ThreadedGoals, NewVarList) '$read_input'(ThreadedGoals, NewVarList)
; C == (';'), !, ; C == p ->
nl,
write(' '),
'$write_eq'(ThreadedGoals, NewVarList, 20),
'$read_input'(ThreadedGoals, NewVarList)
; C == (';') ->
nl, write('; '), false nl, write('; '), false
; C == ('.'), !, ; C == h ->
'$help_message',
'$read_input'(ThreadedGoals, NewVarList)
; C == '.',
nl, write(' ...'), nl 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) :- '$gather_query_vars'([_ = Var | Vars], QueryVars) :-
( var(Var) -> ( var(Var) ->
QueryVars = [Var | QueryVars1], QueryVars = [Var | QueryVars1],