Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
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
stratact
liner
Commits
29f44159
Commit
29f44159
authored
Jul 24, 2016
by
Sehny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
run rustfmt
parent
4d8dd37c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
15 deletions
+18
-15
src/history.rs
src/history.rs
+16
-12
src/main.rs
src/main.rs
+1
-1
src/test.rs
src/test.rs
+1
-2
No files found.
src/history.rs
View file @
29f44159
...
...
@@ -13,19 +13,18 @@ const DEFAULT_MAX_SIZE: usize = 1000;
pub
struct
History
{
// TODO: this should eventually be private
/// Vector of buffers to store history in
pub
buffers
:
VecDeque
<
Buffer
>
,
pub
buffers
:
VecDeque
<
Buffer
>
,
// TODO: Do we need this here? Ion can take care of this.
//pub previous_status: i32,
//
pub previous_status: i32,
/// Store a filename to save history into; if None don't save history
file_name
:
Option
<
String
>
,
file_name
:
Option
<
String
>
,
/// Maximal number of buffers stored in the memory
max_size
:
usize
,
max_size
:
usize
,
/// Maximal number of lines stored in the file
max_file_size
:
usize
,
max_file_size
:
usize
,
}
impl
History
{
/// Create new History structure.
pub
fn
new
()
->
History
{
History
{
...
...
@@ -104,7 +103,9 @@ impl History {
let
mut
file_length
=
0
;
let
file
=
File
::
open
(
file_name
)
.unwrap
();
for
byte
in
file
.bytes
()
{
if
byte
.unwrap_or
(
b
' '
)
==
b
'\n'
{
commands_stored
+=
1
;
}
if
byte
.unwrap_or
(
b
' '
)
==
b
'\n'
{
commands_stored
+=
1
;
}
file_length
+=
1
;
}
(
file_length
,
commands_stored
)
...
...
@@ -122,9 +123,13 @@ impl History {
let
mut
bytes
=
0
;
let
file
=
File
::
open
(
file_name
)
.unwrap
();
for
byte
in
file
.bytes
()
{
if
byte
.unwrap_or
(
b
' '
)
==
b
'\n'
{
matched
+=
1
;
}
if
byte
.unwrap_or
(
b
' '
)
==
b
'\n'
{
matched
+=
1
;
}
bytes
+=
1
;
if
matched
==
commands_to_delete
{
break
}
if
matched
==
commands_to_delete
{
break
;
}
}
bytes
as
u64
};
...
...
@@ -145,11 +150,10 @@ impl History {
Ok
(())
}
Err
(
message
)
=>
Err
(
message
)
Err
(
message
)
=>
Err
(
message
)
,
};
ret
}
}
impl
Index
<
usize
>
for
History
{
...
...
@@ -164,4 +168,4 @@ impl IndexMut<usize> for History {
fn
index_mut
(
&
mut
self
,
index
:
usize
)
->
&
mut
Buffer
{
&
mut
self
.buffers
[
index
]
}
}
\ No newline at end of file
}
src/main.rs
View file @
29f44159
...
...
@@ -20,7 +20,7 @@ fn main() {
Some
(
str
)
=>
file_name
=
str
,
None
=>
{
println!
(
"You have to provide file name"
);
return
return
;
}
}
println!
(
"History file: {}"
,
file_name
);
...
...
src/test.rs
View file @
29f44159
...
...
@@ -103,8 +103,7 @@ fn test_in_file_history_truncating() {
fs
::
remove_file
(
tmp_file
)
.unwrap
();
}
static
TEXT
:
&
'static
str
=
"a
static
TEXT
:
&
'static
str
=
"a
b
c
d
...
...
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