Skip to content

Commit 97f9eec

Browse files
committed
added width setting to displayer
1 parent 6545db6 commit 97f9eec

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

examples/displayer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn main() -> Result<()> {
2929
session
3030
.query_unpaged(
3131
"INSERT INTO examples_ks.basic (a, b, c) VALUES (?, ?, ?)",
32-
(3, 4, "def"),
32+
(3, 4, "lorem Ipsum jest tekstem stosowanym jako przykładowy wypełniacz w przemyśle poligraficznym. Został po raz pierwszy użyty w XV w. przez nieznanego drukarza do wypełnienia tekstem próbnej książki. Pięć wieków później zaczął być używany przemyśle elektronicznym,"),
3333
)
3434
.await?;
3535

scylla/src/transport/query_result.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt::Debug;
22
use std::fmt;
3-
use tabled::{builder::Builder, settings::Style};
3+
use tabled::settings::Width;
4+
use tabled::{builder::Builder, settings::Style,settings::{peaker::Priority}, Tabled};
45

56
use thiserror::Error;
67
use uuid::Uuid;
@@ -445,6 +446,7 @@ impl QueryRowsResult {
445446
pub struct RowsDisplayer<'a> {
446447
query_result: &'a QueryRowsResult,
447448
display_settings: RowsDisplayerSettings,
449+
terminal_width: usize,
448450
}
449451

450452
impl<'a> RowsDisplayer<'a>
@@ -453,9 +455,14 @@ impl<'a> RowsDisplayer<'a>
453455
Self {
454456
query_result,
455457
display_settings: RowsDisplayerSettings::new(),
458+
terminal_width: 80,
456459
}
457460
}
458461

462+
pub fn set_terminal_width(&mut self, terminal_width: usize) {
463+
self.terminal_width = terminal_width;
464+
}
465+
459466
pub fn display(self) {
460467
let row_iter : TypedRowIterator<'_, '_, Row> = match self.query_result.rows::<Row>(){
461468
Ok(row_iter) => row_iter,
@@ -662,7 +669,9 @@ impl fmt::Display for RowsDisplayer<'_> {
662669

663670
// write table to the formatter
664671
let mut table = builder.build();
665-
table.with(Style::modern_rounded());
672+
table.with((Style::modern_rounded(),
673+
Width::wrap(self.terminal_width).priority(Priority::max(true)),
674+
));
666675
write!(f, "{}", table)
667676
}
668677
}

0 commit comments

Comments
 (0)