Skip to content

add option to omit white-only entries from repl history #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/cli_repl.dart
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@ class Repl {
{this.prompt: '',
String continuation,
StatementValidator validator,
this.maxHistory: 50})
this.maxHistory: 50,
this.logWhitespace: true})
: continuation = continuation ?? ' ' * prompt.length,
validator = validator ?? alwaysValid {
_adapter = new ReplAdapter(this);
@@ -45,6 +46,11 @@ class Repl {
///
/// Defaults to 50.
int maxHistory;

/// Should repl history include whitespace-only entries
///
/// Defaults to true
bool logWhitespace;
}

/// Returns true if [text] is a complete statement or false otherwise.
3 changes: 2 additions & 1 deletion lib/src/repl_adapter/vm.dart
Original file line number Diff line number Diff line change
@@ -227,7 +227,8 @@ class ReplAdapter {
String contents = new String.fromCharCodes(buffer);
setCursor(buffer.length);
input(char);
if (repl.history.isEmpty || contents != repl.history.first) {
if ((repl.history.isEmpty || contents != repl.history.first)
&& (contents.trim().isNotEmpty || repl.logWhitespace)) {
repl.history.insert(0, contents);
}
while (repl.history.length > repl.maxHistory) {