Skip to content
Snippets Groups Projects
Commit 9ff808c8 authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

fix: pico.raft_log() broke after updating tarantool-sys

parent bec43c4a
No related branches found
No related tags found
1 merge request!927Gmoshkin/join using batch dml
...@@ -904,40 +904,37 @@ pub(crate) fn setup(config: &PicodataConfig) { ...@@ -904,40 +904,37 @@ pub(crate) fn setup(config: &PicodataConfig) {
let row_sep = |buf: &mut Vec<u8>| { let row_sep = |buf: &mut Vec<u8>| {
match justify_contents { match justify_contents {
Justify::Left => { Justify::Left => {
// NOTE: here and later a special unicode character \u{200b} is used. writeln!(buf, "+{0:-^iw$}+{0:-^tw$}+{0:-<cw$}+", "")
// This is a ZERO WIDTH SPACE and it helps with the tarantool's console.
// The way it works is that tarantool's console when printing the values
// returned from a function will surround string values with quotes if
// for instance they start with a '|' pipe character, which is our case.
// Adding a space before '|' doesn't help but a ZERO WIDTH SPACE
// for what ever reason does. So this is basically a crutch,
// but if it's good enough for tarantool developers, it's good enough for us.
writeln!(buf, "\u{200b}+{0:-^iw$}+{0:-^tw$}+{0:-<cw$}+", "")
} }
Justify::Center => { Justify::Center => {
writeln!(buf, "\u{200b}+{0:-^iw$}+{0:-^tw$}+{0:-^cw$}+", "") writeln!(buf, "+{0:-^iw$}+{0:-^tw$}+{0:-^cw$}+", "")
} }
Justify::Right => { Justify::Right => {
writeln!(buf, "\u{200b}+{0:-^iw$}+{0:-^tw$}+{0:->cw$}+", "") writeln!(buf, "+{0:-^iw$}+{0:-^tw$}+{0:->cw$}+", "")
} }
} }
.unwrap() .unwrap()
}; };
row_sep(&mut buf); row_sep(&mut buf);
write!(buf, "\u{200b}|{index: ^iw$}|{term: ^tw$}|").unwrap(); // NOTE: here and later we use the special uincode \u{01c0} symbol.
// It looks like this `ǀ` (exactly like `|`). We do this,
// because tarantool's yaml handler has special behavior when it
// sees a pipe character at the start of the string. This is the
// same thing as what tarantool's `index:fselect()` is doing.
write!(buf, "\u{01c0}{index: ^iw$}|{term: ^tw$}|").unwrap();
write_contents(&mut buf, contents).unwrap(); write_contents(&mut buf, contents).unwrap();
row_sep(&mut buf); row_sep(&mut buf);
for [index, term, contents] in rows { for [index, term, contents] in rows {
if contents.len() <= cw { if contents.chars().count() <= cw {
write!(buf, "\u{200b}|{index: ^iw$}|{term: ^tw$}|").unwrap(); write!(buf, "\u{01c0}{index: ^iw$}|{term: ^tw$}|").unwrap();
write_contents(&mut buf, &contents).unwrap(); write_contents(&mut buf, &contents).unwrap();
} else { } else {
write!(buf, "\u{200b}|{index: ^iw$}|{term: ^tw$}|").unwrap(); write!(buf, "\u{01c0}{index: ^iw$}|{term: ^tw$}|").unwrap();
write_contents(&mut buf, &contents[..cw]).unwrap(); write_contents(&mut buf, &contents[..cw]).unwrap();
let mut rest = &contents[cw..]; let mut rest = &contents[cw..];
while !rest.is_empty() { while !rest.is_empty() {
let clamped_cw = usize::min(rest.len(), cw); let clamped_cw = usize::min(rest.len(), cw);
write!(buf, "\u{200b}|{blank: ^iw$}|{blank: ^tw$}|", blank = "~",) write!(buf, "\u{01c0}{blank: ^iw$}|{blank: ^tw$}|", blank = "~",)
.unwrap(); .unwrap();
write_contents(&mut buf, &rest[..clamped_cw]).unwrap(); write_contents(&mut buf, &rest[..clamped_cw]).unwrap();
rest = &rest[clamped_cw..]; rest = &rest[clamped_cw..];
...@@ -949,7 +946,11 @@ pub(crate) fn setup(config: &PicodataConfig) { ...@@ -949,7 +946,11 @@ pub(crate) fn setup(config: &PicodataConfig) {
let s = String::from_utf8_lossy(&buf); let s = String::from_utf8_lossy(&buf);
let mut res = vec![]; let mut res = vec![];
for line in s.lines() { for line in s.lines() {
res.push(line.into()); // replace all spaces with the non-breaking space character
// to prevent tarantool's yaml handler from breaking the
// rows which we tried so hard to format correctly
let line = line.replace(' ', "\u{a0}");
res.push(line);
} }
Ok(Some(res)) Ok(Some(res))
}, },
......
...@@ -311,10 +311,12 @@ def test_raft_log(instance: Instance): ...@@ -311,10 +311,12 @@ def test_raft_log(instance: Instance):
# don't care about the vertical lines # don't care about the vertical lines
continue continue
# these are the hacks used to make pretty tables work in tarantool's console
line = line.replace("\u01c0", "|")
line = line.replace("\u00a0", " ")
columns = line.split("|") columns = line.split("|")
columns = [c.strip() for c in columns] columns = [c.strip() for c in columns]
# This is what's to the left of first '|' and it's a special '\u200b' character
columns[0] = ""
# blank out the index column so we don't need to manually update it # blank out the index column so we don't need to manually update it
if columns[1].isdigit(): if columns[1].isdigit():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment