Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cursive-core/src/cursive_root.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::any::Any;
use std::cell::RefCell;
use std::num::NonZeroU32;
#[cfg(feature = "toml")]
use std::path::Path;

use crossbeam_channel::{self, Receiver, Sender};
use parking_lot::RwLock;

use crate::{
backend,
Expand Down Expand Up @@ -123,8 +123,8 @@ impl Cursive {
self.root.layout(size);
}

pub(crate) fn draw(&mut self, buffer: &RwLock<crate::buffer::PrintBuffer>) {
let size = buffer.read().size();
pub(crate) fn draw(&mut self, buffer: &RefCell<crate::buffer::PrintBuffer>) {
let size = buffer.borrow().size();

let printer = Printer::new(size, &self.theme, buffer);

Expand Down
10 changes: 5 additions & 5 deletions cursive-core/src/cursive_run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{backend, buffer, event, Cursive, Vec2};
use parking_lot::RwLock;
use std::borrow::{Borrow, BorrowMut};
use std::cell::RefCell;
use std::time::Duration;

// How long we wait between two empty input polls
Expand All @@ -16,7 +16,7 @@ pub struct CursiveRunner<C> {
siv: C,

backend: Box<dyn backend::Backend>,
buffer: RwLock<buffer::PrintBuffer>,
buffer: RefCell<buffer::PrintBuffer>,

boring_frame_count: u32,
// Last layer sizes of the stack view.
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<C> CursiveRunner<C> {
CursiveRunner {
siv,
backend,
buffer: RwLock::new(buffer::PrintBuffer::new()),
buffer: RefCell::new(buffer::PrintBuffer::new()),
boring_frame_count: 0,
last_sizes: Vec::new(),
}
Expand Down Expand Up @@ -93,9 +93,9 @@ where
self.last_sizes = sizes;
}

self.buffer.write().resize(self.screen_size());
self.buffer.borrow_mut().resize(self.screen_size());
self.siv.borrow_mut().draw(&self.buffer);
self.buffer.write().flush(&*self.backend);
self.buffer.borrow_mut().flush(&*self.backend);
}

/// Performs the first half of `Self::step()`.
Expand Down
24 changes: 10 additions & 14 deletions cursive-core/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use crate::with::With;
use crate::Vec2;

use enumset::EnumSet;
use parking_lot::RwLock;
use std::cell::Cell;
use std::cell::{Cell, RefCell};
use std::cmp::min;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
Expand Down Expand Up @@ -70,15 +69,15 @@ pub struct Printer<'a, 'b> {
current_style: Cell<ConcreteStyle>,

/// Backend used to actually draw things
buffer: &'b RwLock<PrintBuffer>,
buffer: &'b RefCell<PrintBuffer>,
}

impl<'a, 'b> Printer<'a, 'b> {
/// Creates a new printer on the given window.
///
/// But nobody needs to know that.
#[doc(hidden)]
pub fn new<T: Into<Vec2>>(size: T, theme: &'a Theme, buffer: &'b RwLock<PrintBuffer>) -> Self {
pub fn new<T: Into<Vec2>>(size: T, theme: &'a Theme, buffer: &'b RefCell<PrintBuffer>) -> Self {
let size = size.into();
Printer {
offset: Vec2::zero(),
Expand All @@ -105,7 +104,7 @@ impl<'a, 'b> Printer<'a, 'b> {
///
/// This is the size of the entire terminal, not just the area this printer can write into.
pub fn buffer_size(&self) -> Vec2 {
self.buffer.read().size()
self.buffer.borrow().size()
}

/// Clear the screen.
Expand All @@ -115,7 +114,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// Users rarely need to call this directly.
pub fn clear(&self) {
let color = self.theme.palette[PaletteColor::Background];
self.buffer.write().fill(
self.buffer.borrow_mut().fill(
" ",
ColorPair {
front: color,
Expand Down Expand Up @@ -258,7 +257,7 @@ impl<'a, 'b> Printer<'a, 'b> {

let start = start + self.offset;
self.buffer
.write()
.borrow_mut()
.print_at(start, text, self.current_style());
}

Expand Down Expand Up @@ -294,7 +293,7 @@ impl<'a, 'b> Printer<'a, 'b> {
let start = start + self.offset;
for y in 0..height {
self.buffer
.write()
.borrow_mut()
.print_at(start + (0, y), c, self.current_style());
}
}
Expand All @@ -304,7 +303,7 @@ impl<'a, 'b> Printer<'a, 'b> {
where
F: FnOnce(&mut Window<'_>) -> R,
{
let mut buffer = self.buffer.write();
let mut buffer = self.buffer.borrow_mut();
let mut window = buffer
.window(self.output_window())
.expect("printer size exceeds backend size");
Expand Down Expand Up @@ -362,7 +361,7 @@ impl<'a, 'b> Printer<'a, 'b> {
let repetitions = min(width, self.output_size.x - start.x) / c_width;

let mut start = start + self.offset;
let mut buffer = self.buffer.write();
let mut buffer = self.buffer.borrow_mut();
let style = self.current_style();
for _ in 0..repetitions {
buffer.print_at(start, c, style);
Expand Down Expand Up @@ -424,10 +423,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply the given color on prints.
///
/// Does not change the current set of active effects (bold/underline/...).
pub fn with_color<F>(&self, c: ColorStyle, f: F)
where
F: FnOnce(&Printer),
{
pub fn with_color<F: FnOnce(&Printer)>(&self, c: ColorStyle, f: F) {
let sub = self.clone().with(|sub| sub.set_color(c));

f(&sub);
Expand Down