Skip to content

Commit fd10622

Browse files
committed
added width setting to displayer
1 parent 3bbba59 commit fd10622

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/response/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;
@@ -456,6 +457,7 @@ impl QueryRowsResult {
456457
pub struct RowsDisplayer<'a> {
457458
query_result: &'a QueryRowsResult,
458459
display_settings: RowsDisplayerSettings,
460+
terminal_width: usize,
459461
}
460462

461463
impl<'a> RowsDisplayer<'a>
@@ -464,9 +466,14 @@ impl<'a> RowsDisplayer<'a>
464466
Self {
465467
query_result,
466468
display_settings: RowsDisplayerSettings::new(),
469+
terminal_width: 80,
467470
}
468471
}
469472

473+
pub fn set_terminal_width(&mut self, terminal_width: usize) {
474+
self.terminal_width = terminal_width;
475+
}
476+
470477
pub fn display(self) {
471478
let row_iter : TypedRowIterator<'_, '_, Row> = match self.query_result.rows::<Row>(){
472479
Ok(row_iter) => row_iter,
@@ -673,7 +680,9 @@ impl fmt::Display for RowsDisplayer<'_> {
673680

674681
// write table to the formatter
675682
let mut table = builder.build();
676-
table.with(Style::modern_rounded());
683+
table.with((Style::modern_rounded(),
684+
Width::wrap(self.terminal_width).priority(Priority::max(true)),
685+
));
677686
write!(f, "{}", table)
678687
}
679688
}

0 commit comments

Comments
 (0)