Skip to content

Commit

Permalink
fix warnings and compile errors due to ratatui v0.28 update
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Aug 7, 2024
1 parent 5d77bf8 commit 9650a11
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 21 deletions.
23 changes: 17 additions & 6 deletions bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use ratatui::backend::{Backend, WindowSize};
use ratatui::buffer::Cell;
use ratatui::layout::{Rect, Size};
use ratatui::layout::{Position, Size};
use ratatui::Terminal;
use std::io;
use tui_textarea::TextArea;
Expand Down Expand Up @@ -75,10 +75,8 @@ impl Backend for DummyBackend {
}

#[inline]
fn size(&self) -> io::Result<Rect> {
Ok(Rect {
x: 0,
y: 0,
fn size(&self) -> io::Result<Size> {
Ok(Size {
width: self.width,
height: self.height,
})
Expand All @@ -102,6 +100,19 @@ impl Backend for DummyBackend {
fn flush(&mut self) -> io::Result<()> {
Ok(())
}

#[inline]
fn get_cursor_position(&mut self) -> io::Result<Position> {
let (x, y) = self.cursor;
Ok(Position { x, y })
}

#[inline]
fn set_cursor_position<P: Into<Position>>(&mut self, position: P) -> io::Result<()> {
let Position { x, y } = position.into();
self.cursor = (x, y);
Ok(())
}
}

#[inline]
Expand All @@ -116,6 +127,6 @@ pub trait TerminalExt {
impl TerminalExt for Terminal<DummyBackend> {
#[inline]
fn draw_textarea(&mut self, textarea: &TextArea<'_>) {
self.draw(|f| f.render_widget(textarea, f.size())).unwrap();
self.draw(|f| f.render_widget(textarea, f.area())).unwrap();
}
}
2 changes: 1 addition & 1 deletion examples/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl<'a> Editor<'a> {
);

self.term.draw(|f| {
let chunks = layout.split(f.size());
let chunks = layout.split(f.area());

if search_height > 0 {
f.render_widget(&self.search.textarea, chunks[0]);
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> io::Result<()> {

loop {
term.draw(|f| {
f.render_widget(&textarea, f.size());
f.render_widget(&textarea, f.area());
})?;
match crossterm::event::read()?.into() {
Input { key: Key::Esc, .. } => break,
Expand Down
2 changes: 1 addition & 1 deletion examples/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() -> io::Result<()> {

loop {
term.draw(|f| {
let chunks = layout.split(f.size());
let chunks = layout.split(f.area());
f.render_widget(&textarea, chunks[0]);
})?;

Expand Down
2 changes: 1 addition & 1 deletion examples/single_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() -> io::Result<()> {

loop {
term.draw(|f| {
let chunks = layout.split(f.size());
let chunks = layout.split(f.area());
f.render_widget(&textarea, chunks[0]);
})?;

Expand Down
2 changes: 1 addition & 1 deletion examples/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() -> io::Result<()> {

loop {
term.draw(|f| {
let chunks = layout.split(f.size());
let chunks = layout.split(f.area());
for (textarea, chunk) in textarea.iter().zip(chunks.iter()) {
f.render_widget(textarea, *chunk);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/termion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() -> Result<(), Box<dyn Error>> {
Event::Tick => {}
}
term.draw(|f| {
f.render_widget(&textarea, f.size());
f.render_widget(&textarea, f.area());
})?;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/termwiz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// The event loop
loop {
term.draw(|f| {
f.render_widget(&textarea, f.size());
f.render_widget(&textarea, f.area());
})?;

if let Some(input) = term
Expand Down
2 changes: 1 addition & 1 deletion examples/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> io::Result<()> {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(height), Constraint::Min(0)])
.split(f.size());
.split(f.area());
f.render_widget(&textarea, chunks[0]);
})?;
match crossterm::event::read()?.into() {
Expand Down
2 changes: 1 addition & 1 deletion examples/vim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ fn main() -> io::Result<()> {
let mut vim = Vim::new(Mode::Normal);

loop {
term.draw(|f| f.render_widget(&textarea, f.size()))?;
term.draw(|f| f.render_widget(&textarea, f.area()))?;

vim = match vim.transition(crossterm::event::read()?.into(), &mut textarea) {
Transition::Mode(mode) if vim.mode != mode => {
Expand Down
8 changes: 4 additions & 4 deletions src/textarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ impl fmt::Display for YankText {
/// println!("Lines: {:?}", textarea.lines());
/// ```
///
/// It implements [`ratatui::widgets::Widget`] trait so it can be rendered to a
/// terminal screen via [`ratatui::terminal::Frame::render_widget`] method.
/// It implements [`ratatui::widgets::Widget`] trait so it can be rendered to a terminal screen via
/// [`ratatui::Frame::render_widget`] method.
/// ```no_run
/// use ratatui::backend::CrosstermBackend;
/// use ratatui::layout::{Constraint, Direction, Layout};
Expand All @@ -96,7 +96,7 @@ impl fmt::Display for YankText {
///
/// loop {
/// term.draw(|f| {
/// let chunks = layout.split(f.size());
/// let chunks = layout.split(f.area());
/// f.render_widget(&textarea, chunks[0]);
/// }).unwrap();
///
Expand Down Expand Up @@ -1616,7 +1616,7 @@ impl<'a> TextArea<'a> {
}

/// Build a ratatui (or tui-rs) widget to render the current state of the textarea. The widget instance returned
/// from this method can be rendered with [`ratatui::terminal::Frame::render_widget`].
/// from this method can be rendered with [`ratatui::Frame::render_widget`].
///
/// This method was deprecated at v0.5.3 and is no longer necessary. Instead you can directly pass `&TextArea`
/// reference to the `Frame::render_widget` method call.
Expand Down
4 changes: 2 additions & 2 deletions src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use tui::text::Spans as Line;
// instance. In the case, the TextArea instance cannot be accessed from any other objects since it is mutablly
// borrowed.
//
// `ratatui::terminal::Frame::render_stateful_widget` would be an assumed way to render a stateful widget. But at this
// point we stick with using `ratatui::terminal::Frame::render_widget` because it is simpler API. Users don't need to
// `ratatui::Frame::render_stateful_widget` would be an assumed way to render a stateful widget. But at this
// point we stick with using `ratatui::Frame::render_widget` because it is simpler API. Users don't need to
// manage states of textarea instances separately.
// https://docs.rs/ratatui/latest/ratatui/terminal/struct.Frame.html#method.render_stateful_widget
#[derive(Default, Debug)]
Expand Down

0 comments on commit 9650a11

Please sign in to comment.