Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-rust-mirrors-rustyline
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-rust-mirrors-rustyline
Commits
8b14661e
Commit
8b14661e
authored
8 years ago
by
gwenn
Browse files
Options
Downloads
Patches
Plain Diff
Make History ignore space/dups configurable (#50)
parent
f22d3c27
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/example.rs
+1
-1
1 addition, 1 deletion
examples/example.rs
src/history.rs
+19
-6
19 additions, 6 deletions
src/history.rs
src/lib.rs
+10
-0
10 additions, 0 deletions
src/lib.rs
with
30 additions
and
7 deletions
examples/example.rs
+
1
−
1
View file @
8b14661e
...
...
@@ -15,7 +15,7 @@ static PROMPT: &'static str = ">> ";
fn
main
()
{
let
c
=
FilenameCompleter
::
new
();
let
mut
rl
=
Editor
::
new
();
let
mut
rl
=
Editor
::
new
()
.history_ignore_space
(
true
)
;
rl
.set_completer
(
Some
(
&
c
));
if
let
Err
(
_
)
=
rl
.load_history
(
"history.txt"
)
{
println!
(
"No previous history."
);
...
...
This diff is collapsed.
Click to expand it.
src/history.rs
+
19
−
6
View file @
8b14661e
...
...
@@ -9,6 +9,8 @@ use super::Result;
pub
struct
History
{
entries
:
VecDeque
<
String
>
,
max_len
:
usize
,
ignore_space
:
bool
,
ignore_dups
:
bool
,
}
const
DEFAULT_HISTORY_MAX_LEN
:
usize
=
100
;
...
...
@@ -18,9 +20,19 @@ impl History {
History
{
entries
:
VecDeque
::
new
(),
max_len
:
DEFAULT_HISTORY_MAX_LEN
,
ignore_space
:
true
,
ignore_dups
:
true
,
}
}
pub
fn
ignore_space
(
&
mut
self
,
yes
:
bool
)
{
self
.ignore_space
=
yes
;
}
pub
fn
ignore_dups
(
&
mut
self
,
yes
:
bool
)
{
self
.ignore_dups
=
yes
;
}
/// Return the history entry at position `index`, starting from 0.
pub
fn
get
(
&
self
,
index
:
usize
)
->
Option
<&
String
>
{
self
.entries
.get
(
index
)
...
...
@@ -31,14 +43,15 @@ impl History {
if
self
.max_len
==
0
{
return
false
;
}
if
line
.is_empty
()
||
line
.chars
()
.next
()
.map_or
(
true
,
|
c
|
c
.is_whitespace
())
{
// ignorespace
if
line
.is_empty
()
||
(
self
.ignore_space
&&
line
.chars
()
.next
()
.map_or
(
true
,
|
c
|
c
.is_whitespace
()))
{
return
false
;
}
if
let
Some
(
s
)
=
self
.entries
.back
()
{
if
s
==
line
{
// ignoredups
return
false
;
if
self
.ignore_dups
{
if
let
Some
(
s
)
=
self
.entries
.back
()
{
if
s
==
line
{
return
false
;
}
}
}
if
self
.entries
.len
()
==
self
.max_len
{
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
10
−
0
View file @
8b14661e
...
...
@@ -936,6 +936,16 @@ impl<'completer> Editor<'completer> {
}
}
pub
fn
history_ignore_space
(
mut
self
,
yes
:
bool
)
->
Editor
<
'completer
>
{
self
.history
.ignore_space
(
yes
);
self
}
pub
fn
history_ignore_dups
(
mut
self
,
yes
:
bool
)
->
Editor
<
'completer
>
{
self
.history
.ignore_dups
(
yes
);
self
}
/// Load the history from the specified file.
pub
fn
load_history
<
P
:
AsRef
<
Path
>
+
?
Sized
>
(
&
mut
self
,
path
:
&
P
)
->
Result
<
()
>
{
self
.history
.load
(
path
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment