Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
liner
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AdminXVII
liner
Commits
a125f7b5
Commit
a125f7b5
authored
Apr 02, 2019
by
AdminXVII
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ignore timestamps (lines starting with #)
parent
741f36fb
Pipeline
#3614
passed with stage
in 59 minutes and 32 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
25 deletions
+43
-25
src/history.rs
src/history.rs
+43
-25
No files found.
src/history.rs
View file @
a125f7b5
...
...
@@ -2,9 +2,9 @@ use super::*;
use
std
::{
collections
::{
vec_deque
,
VecDeque
},
io
::{
BufRead
,
BufReader
,
BufWriter
},
fs
::
File
,
io
::{
self
,
Write
},
io
::{
BufRead
,
BufReader
,
BufWriter
},
iter
::
IntoIterator
,
ops
::
Index
,
ops
::
IndexMut
,
...
...
@@ -44,7 +44,10 @@ impl History {
}
/// Set history file name and at the same time load the history.
pub
fn
set_file_name_and_load_history
<
P
:
AsRef
<
Path
>>
(
&
mut
self
,
path
:
P
)
->
io
::
Result
<
String
>
{
pub
fn
set_file_name_and_load_history
<
P
:
AsRef
<
Path
>>
(
&
mut
self
,
path
:
P
,
)
->
io
::
Result
<
String
>
{
let
status
;
let
path
=
path
.as_ref
();
let
file
=
if
path
.exists
()
{
...
...
@@ -57,7 +60,11 @@ impl History {
let
reader
=
BufReader
::
new
(
file
);
for
line
in
reader
.lines
()
{
match
line
{
Ok
(
line
)
=>
self
.buffers
.push_back
(
Buffer
::
from
(
line
)),
Ok
(
line
)
=>
{
if
!
line
.starts_with
(
'#'
)
{
self
.buffers
.push_back
(
Buffer
::
from
(
line
));
}
}
Err
(
_
)
=>
break
,
}
}
...
...
@@ -109,16 +116,22 @@ impl History {
}
fn
get_match
<
I
>
(
&
self
,
vals
:
I
,
search_term
:
&
Buffer
)
->
Option
<
usize
>
where
I
:
Iterator
<
Item
=
usize
>
where
I
:
Iterator
<
Item
=
usize
>
,
{
vals
.filter_map
(|
i
|
self
.buffers
.get
(
i
)
.map
(|
t
|
(
i
,
t
)))
.filter
(|(
_
i
,
tested
)|
tested
.starts_with
(
search_term
))
.next
()
.map
(|(
i
,
_
)|
i
)
.next
()
.map
(|(
i
,
_
)|
i
)
}
/// Go through the history and try to find an index (newest to oldest) which starts the same
/// as the new buffer given to this function as argument. Starts at curr_position. Does no wrap.
pub
fn
get_newest_match
(
&
self
,
curr_position
:
Option
<
usize
>
,
new_buff
:
&
Buffer
,
)
->
Option
<
usize
>
{
pub
fn
get_newest_match
(
&
self
,
curr_position
:
Option
<
usize
>
,
new_buff
:
&
Buffer
,
)
->
Option
<
usize
>
{
let
pos
=
curr_position
.unwrap_or_else
(||
self
.buffers
.len
());
if
pos
>
0
{
self
.get_match
((
0
..
pos
)
.rev
(),
new_buff
)
...
...
@@ -129,28 +142,31 @@ impl History {
pub
fn
get_history_subset
(
&
self
,
search_term
:
&
Buffer
)
->
Vec
<
usize
>
{
let
mut
v
:
Vec
<
usize
>
=
Vec
::
new
();
let
mut
ret
:
Vec
<
usize
>
=
(
0
..
self
.len
())
.filter
(|
i
|
{
if
let
Some
(
tested
)
=
self
.buffers
.get
(
*
i
)
{
let
starts
=
tested
.starts_with
(
search_term
);
let
contains
=
tested
.contains
(
search_term
);
if
starts
{
v
.push
(
*
i
);
let
mut
ret
:
Vec
<
usize
>
=
(
0
..
self
.len
())
.filter
(|
i
|
{
if
let
Some
(
tested
)
=
self
.buffers
.get
(
*
i
)
{
let
starts
=
tested
.starts_with
(
search_term
);
let
contains
=
tested
.contains
(
search_term
);
if
starts
{
v
.push
(
*
i
);
}
if
contains
&&
!
starts
&&
!
tested
.equals
(
search_term
)
{
return
true
;
}
}
if
contains
&&
!
starts
&&
!
tested
.equals
(
search_term
)
{
return
true
;
}
}
return
false
;
})
.collect
();
return
false
;
})
.collect
();
ret
.append
(
&
mut
v
);
ret
}
pub
fn
search_index
(
&
self
,
search_term
:
&
Buffer
)
->
Vec
<
usize
>
{
(
0
..
self
.len
())
.filter_map
(|
i
|
self
.buffers
.get
(
i
)
.map
(|
t
|
(
i
,
t
)))
pub
fn
search_index
(
&
self
,
search_term
:
&
Buffer
)
->
Vec
<
usize
>
{
(
0
..
self
.len
())
.filter_map
(|
i
|
self
.buffers
.get
(
i
)
.map
(|
t
|
(
i
,
t
)))
.filter
(|(
_
i
,
tested
)|
tested
.contains
(
search_term
))
.map
(|(
i
,
_
)|
i
)
.collect
()
.map
(|(
i
,
_
)|
i
)
.collect
()
}
/// Get the history file name.
...
...
@@ -170,9 +186,11 @@ impl History {
}
}
let
mut
file
=
BufWriter
::
new
(
File
::
create
(
&
file_name
)
// It's safe to unwrap, because the file has be loaded by this time
.unwrap
());
let
mut
file
=
BufWriter
::
new
(
File
::
create
(
&
file_name
)
// It's safe to unwrap, because the file has be loaded by this time
.unwrap
(),
);
// Write the commands to the history file.
for
command
in
self
.buffers
.iter
()
.cloned
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment