Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Merge requests
!334
feat(picolib): picolib.raft_log { justify_contents = ['left'|'center'|'right'] }
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
feat(picolib): picolib.raft_log { justify_contents = ['left'|'center'|'right'] }
feat/picolib/raft-log-justify-contents
into
master
Overview
0
Commits
1
Pipelines
3
Changes
1
Merged
Georgy Moshkin
requested to merge
feat/picolib/raft-log-justify-contents
into
master
2 years ago
Overview
0
Commits
1
Pipelines
3
Changes
1
Expand
Edited
2 years ago
by
Georgy Moshkin
0
0
Merge request reports
Compare
master
version 2
59b81c9b
2 years ago
version 1
da675e5a
2 years ago
master (base)
and
latest version
latest version
be7183bd
1 commit,
2 years ago
version 2
59b81c9b
1 commit,
2 years ago
version 1
da675e5a
1 commit,
2 years ago
1 file
+
42
−
21
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/main.rs
+
42
−
21
Options
@@ -267,15 +267,28 @@ fn picolib_setup(args: &args::Run) {
.unwrap
();
}
#[derive(::tarantool::tlua::LuaRead,
Default,
Clone,
Copy)]
enum
Justify
{
Left
,
#[default]
Center
,
Right
,
}
#[derive(::tarantool::tlua::LuaRead)]
struct
RaftLogOpts
{
return_string
:
Option
<
bool
>
,
justify_contents
:
Option
<
Justify
>
,
}
luamod
.set
(
"raft_log"
,
tlua
::
function1
(
|
opts
:
Option
<
RaftLogOpts
>
|
->
traft
::
Result
<
Option
<
String
>>
{
let
return_string
=
opts
.and_then
(|
o
|
o
.return_string
)
.unwrap_or
(
false
);
let
mut
return_string
=
false
;
let
mut
justify_contents
=
Default
::
default
();
if
let
Some
(
opts
)
=
opts
{
return_string
=
opts
.return_string
.unwrap_or
(
false
);
justify_contents
=
opts
.justify_contents
.unwrap_or_default
();
}
let
header
=
[
"index"
,
"term"
,
"lc"
,
"contents"
];
let
[
index
,
term
,
lc
,
contents
]
=
header
;
let
mut
rows
=
vec!
[];
@@ -318,40 +331,48 @@ fn picolib_setup(args: &args::Run) {
use
std
::
io
::
Write
;
let
mut
buf
:
Vec
<
u8
>
=
Vec
::
with_capacity
(
512
);
let
write_contents
=
move
|
buf
:
&
mut
Vec
<
u8
>
,
contents
:
&
str
|
match
justify_contents
{
Justify
::
Left
=>
writeln!
(
buf
,
"{contents: <cw$}|"
),
Justify
::
Center
=>
writeln!
(
buf
,
"{contents: ^cw$}|"
),
Justify
::
Right
=>
writeln!
(
buf
,
"{contents: >cw$}|"
),
};
let
row_sep
=
|
buf
:
&
mut
Vec
<
u8
>
|
{
writeln!
(
buf
,
"+{0:-^iw$}+{0:-^tw$}+{0:-^lw$}+{0:-^cw$}+"
,
""
)
.unwrap
()
match
justify_contents
{
Justify
::
Left
=>
{
writeln!
(
buf
,
"+{0:-^iw$}+{0:-^tw$}+{0:-^lw$}+{0:-<cw$}+"
,
""
)
}
Justify
::
Center
=>
{
writeln!
(
buf
,
"+{0:-^iw$}+{0:-^tw$}+{0:-^lw$}+{0:-^cw$}+"
,
""
)
}
Justify
::
Right
=>
{
writeln!
(
buf
,
"+{0:-^iw$}+{0:-^tw$}+{0:-^lw$}+{0:->cw$}+"
,
""
)
}
}
.unwrap
()
};
row_sep
(
&
mut
buf
);
writeln!
(
buf
,
"|{index: ^iw$}|{term: ^tw$}|{lc: ^lw$}|{contents: ^cw$}|"
)
.unwrap
();
write!
(
buf
,
"|{index: ^iw$}|{term: ^tw$}|{lc: ^lw$}|"
)
.unwrap
();
write_contents
(
&
mut
buf
,
contents
)
.unwrap
();
row_sep
(
&
mut
buf
);
for
[
index
,
term
,
lc
,
contents
]
in
rows
{
if
contents
.len
()
<=
cw
{
writeln!
(
buf
,
"|{index: ^iw$}|{term: ^tw$}|{lc: ^lw$}|{contents: ^cw$}|"
)
.unwrap
();
write!
(
buf
,
"|{index: ^iw$}|{term: ^tw$}|{lc: ^lw$}|"
)
.unwrap
();
write_contents
(
&
mut
buf
,
&
contents
)
.unwrap
();
}
else
{
writeln!
(
buf
,
"|{index: ^iw$}|{term: ^tw$}|{lc: ^lw$}|{contents: ^cw$}|"
,
contents
=
&
contents
[
..
cw
],
)
.unwrap
();
write!
(
buf
,
"|{index: ^iw$}|{term: ^tw$}|{lc: ^lw$}|"
)
.unwrap
();
write_contents
(
&
mut
buf
,
&
contents
[
..
cw
])
.unwrap
();
let
mut
rest
=
&
contents
[
cw
..
];
while
!
rest
.is_empty
()
{
let
clamped_cw
=
usize
::
min
(
rest
.len
(),
cw
);
write
ln
!
(
write!
(
buf
,
"|{blank: ^iw$}|{blank: ^tw$}|{blank: ^lw$}|
{contents: ^cw$}|
"
,
"|{blank: ^iw$}|{blank: ^tw$}|{blank: ^lw$}|"
,
blank
=
"~"
,
contents
=
&
rest
[
..
clamped_cw
],
)
.unwrap
();
write_contents
(
&
mut
buf
,
&
rest
[
..
clamped_cw
])
.unwrap
();
rest
=
&
rest
[
clamped_cw
..
];
}
}
Loading