Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Jun 5, 2024
1 parent 7aa28c7 commit 760999d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
15 changes: 9 additions & 6 deletions cursive-core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl PrintBuffer {
PrintBuffer {
active_buffer: Vec::new(),
frozen_buffer: Vec::new(),
current_style : ConcreteStyle::terminal_default(),
current_style: ConcreteStyle::terminal_default(),
size: Vec2::ZERO,
}
}
Expand Down Expand Up @@ -183,7 +183,10 @@ impl PrintBuffer {
// TODO: Use some WithWidth(&str, usize) to not re-compute width a thousand times
for g in text.graphemes(true) {
let width = g.width();
self.set_cell(pos, g, width, style);
if width == 0 {
continue;
}
self.set_cell(pos, g, CellWidth::from_usize(width), style);
pos.x += width;
}
}
Expand All @@ -207,19 +210,19 @@ impl PrintBuffer {
/// Set a cell.
///
/// width _must_ be grapheme.width().
fn set_cell(&mut self, pos: Vec2, grapheme: &str, width: usize, style: ConcreteStyle) {
debug_assert_eq!(width, grapheme.width());
fn set_cell(&mut self, pos: Vec2, grapheme: &str, width: CellWidth, style: ConcreteStyle) {
debug_assert_eq!(width.as_usize(), grapheme.width());

let id = self.cell_id(pos);

let cell = &mut self.active_buffer[id].get_or_insert_with(Default::default);
cell.style = style;
cell.text.clear();
cell.text.push_str(grapheme);
cell.width = CellWidth::from_usize(width);
cell.width = width;

// If this is a double-wide grapheme, mark the next cell as blocked.
for dx in 1..width {
for dx in 1..width.as_usize() {
if pos.x + dx >= self.size.x {
break;
}
Expand Down
13 changes: 4 additions & 9 deletions cursive-core/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,11 @@ impl<'a, 'b> Printer<'a, 'b> {
/// ```rust
/// # use cursive_core::Printer;
/// # use cursive_core::theme;
/// # use cursive_core::buffer;
/// # let b = buffer::Dummy::init();
/// # let t = theme::load_default();
/// # let printer = Printer::new((6,4), &t, &*b);
/// # fn with_printer(printer: &Printer) {
/// printer.with_style(theme::PaletteStyle::Highlight, |printer| {
/// printer.print((0, 0), "This text is highlighted!");
/// });
/// # }
/// ```
pub fn with_style<F, T>(&self, style: T, f: F)
where
Expand Down Expand Up @@ -485,12 +483,9 @@ impl<'a, 'b> Printer<'a, 'b> {
///
/// ```rust
/// # use cursive_core::Printer;
/// # use cursive_core::theme;
/// # use cursive_core::buffer;
/// # let b = buffer::Dummy::init();
/// # let t = theme::load_default();
/// # let printer = Printer::new((6,4), &t, &*b);
/// # fn with_printer(printer: &Printer) {
/// printer.print_box((0, 0), (6, 4), false);
/// # }
/// ```
pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(&self, start: T, size: S, invert: bool) {
let start = start.into();
Expand Down
2 changes: 0 additions & 2 deletions cursive-core/src/utils/lines/spans/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ fn test_line_breaks() {

let rows: Vec<_> = iter.map(|row| row.resolve(&input)).collect();

// println!("{:?}", rows);

assert_eq!(
&rows[..],
&[
Expand Down
7 changes: 3 additions & 4 deletions cursive-core/src/view/scroll_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,14 @@ impl ScrollBase {
/// # Examples
///
/// ```rust
/// # #[allow(deprecated)]
/// # fn with_printer(printer: &cursive_core::Printer) {
/// # let scrollbase = cursive_core::view::ScrollBase::new();
/// # let b = cursive_core::backend::Dummy::init();
/// # let t = cursive_core::theme::load_default();
/// # let printer = &cursive_core::Printer::new((5,1), &t, &*b);
/// # let printer = &printer;
/// let lines = ["Line 1", "Line number 2"];
/// scrollbase.draw(printer, |printer, i| {
/// printer.print((0, 0), lines[i]);
/// });
/// # }
/// ```
pub fn draw<F>(&self, printer: &Printer, line_drawer: F)
where
Expand Down

0 comments on commit 760999d

Please sign in to comment.