Skip to content

Commit 2979527

Browse files
committed
readyset-repl: Render bytes as UTF-8
Format REPL table cells through a helper that detects DfValue::ByteArray and attempts UTF-8 decoding. This keeps text payloads readable while preserving the existing fallback for non-UTF-8 bytes. AI-Use: level:v Change-Id: I604184848cbba4d75ff896ca7b803f286a6a6964 Reviewed-on: https://gerrit.readyset.name/c/readyset/+/11238 Tested-by: Buildkite CI Reviewed-by: Jason Brown <jason.b@readyset.io>
1 parent 4193f82 commit 2979527

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

readyset-repl/src/main.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use database_utils::{
88
DatabaseConnection, DatabaseStatement, DatabaseType, DatabaseURL, QueryableConnection,
99
};
1010
use postgres_types::Type;
11-
use prettytable::Table;
11+
use prettytable::{Cell, Row, Table};
1212
use readyset_data::DfValue;
1313
use rustyline::Editor;
1414
use rustyline::error::ReadlineError;
@@ -248,11 +248,27 @@ fn print_result(rows: Vec<Vec<DfValue>>) {
248248
let mut table = Table::new();
249249
table.set_format(*prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
250250
for row in rows {
251-
table.add_row(row.into());
251+
let cells = row
252+
.iter()
253+
.map(|value| Cell::new(&format_df_value(value)))
254+
.collect();
255+
table.add_row(Row::new(cells));
252256
}
253257
print!("\n{table}");
254258
}
255259

260+
/// Pretty-print [`DfValue`]s for the REPL.
261+
fn format_df_value(value: &DfValue) -> String {
262+
match value {
263+
// Try to render byte arrays as UTF-8 for friendlier output when the contents are text.
264+
DfValue::ByteArray(bytes) => match std::str::from_utf8(bytes) {
265+
Ok(text) => text.to_string(),
266+
Err(_) => value.to_string(),
267+
},
268+
_ => value.to_string(),
269+
}
270+
}
271+
256272
#[derive(Completer, Hinter, Helper, Highlighter)]
257273
struct WaitForSemicolon;
258274

0 commit comments

Comments
 (0)