mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-10-24 13:50:42 +08:00
Update to ratatui 0.29.0
This commit is contained in:
+21
-25
@@ -15,9 +15,8 @@ use super::event::Event;
|
||||
|
||||
pub type Backend<S> = TermionBackendExt<S>;
|
||||
|
||||
pub type InlineTerminal = ratatui::terminal::Terminal<Backend<RawTerminal<io::Stdout>>>;
|
||||
pub type FullscreenTerminal =
|
||||
ratatui::terminal::Terminal<Backend<AlternateScreen<RawTerminal<io::Stdout>>>>;
|
||||
pub type InlineTerminal = ratatui::Terminal<Backend<RawTerminal<io::Stdout>>>;
|
||||
pub type FullscreenTerminal = ratatui::Terminal<Backend<AlternateScreen<RawTerminal<io::Stdout>>>>;
|
||||
|
||||
pub enum Terminal {
|
||||
Inline(InlineTerminal),
|
||||
@@ -32,8 +31,9 @@ impl Terminal {
|
||||
}
|
||||
Terminal::Inline(inner) => {
|
||||
// TODO(erikli): Check if still needed.
|
||||
let size = inner.get_frame().size();
|
||||
inner.set_cursor(size.x, size.y)?;
|
||||
let area = inner.get_frame().area();
|
||||
let position = Position::new(area.x, area.y);
|
||||
inner.set_cursor_position(position)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +59,8 @@ impl TryFrom<Viewport> for Terminal {
|
||||
Viewport::Fullscreen => {
|
||||
let stdout = io::stdout().into_raw_mode()?.into_alternate_screen()?;
|
||||
let options = TerminalOptions { viewport };
|
||||
let mut terminal = ratatui::terminal::Terminal::with_options(
|
||||
TermionBackendExt::new(stdout),
|
||||
options,
|
||||
)?;
|
||||
let mut terminal =
|
||||
ratatui::Terminal::with_options(TermionBackendExt::new(stdout), options)?;
|
||||
|
||||
terminal.clear()?;
|
||||
|
||||
@@ -71,10 +69,8 @@ impl TryFrom<Viewport> for Terminal {
|
||||
_ => {
|
||||
let stdout = io::stdout().into_raw_mode()?;
|
||||
let options = TerminalOptions { viewport };
|
||||
let terminal = ratatui::terminal::Terminal::with_options(
|
||||
TermionBackendExt::new(stdout),
|
||||
options,
|
||||
)?;
|
||||
let terminal =
|
||||
ratatui::Terminal::with_options(TermionBackendExt::new(stdout), options)?;
|
||||
|
||||
Ok(Terminal::Inline(terminal))
|
||||
}
|
||||
@@ -88,7 +84,7 @@ pub struct TermionBackendExt<W>
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
cursor: Option<(u16, u16)>,
|
||||
cursor: Option<Position>,
|
||||
inner: TermionBackend<W>,
|
||||
}
|
||||
|
||||
@@ -124,20 +120,20 @@ impl<W: Write> ratatui::backend::Backend for TermionBackendExt<W> {
|
||||
self.inner.show_cursor()
|
||||
}
|
||||
|
||||
fn get_cursor(&mut self) -> io::Result<(u16, u16)> {
|
||||
match self.inner.get_cursor() {
|
||||
Ok((x, y)) => {
|
||||
let cursor = (x.saturating_sub(0), y.saturating_sub(0));
|
||||
self.cursor = Some(cursor);
|
||||
Ok(cursor)
|
||||
fn get_cursor_position(&mut self) -> io::Result<Position> {
|
||||
match self.inner.get_cursor_position() {
|
||||
Ok(position) => {
|
||||
self.cursor = Some(position);
|
||||
Ok(position)
|
||||
}
|
||||
Err(_) => Ok(self.cursor.unwrap_or((0, 0))),
|
||||
Err(_) => Ok(self.cursor.unwrap_or_default()),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> {
|
||||
self.cursor = Some((x, y));
|
||||
self.inner.set_cursor(x, y)
|
||||
fn set_cursor_position<P: Into<Position>>(&mut self, position: P) -> io::Result<()> {
|
||||
self.cursor = Some(position.into());
|
||||
self.inner
|
||||
.set_cursor_position(self.cursor.unwrap_or_default())
|
||||
}
|
||||
|
||||
fn clear(&mut self) -> io::Result<()> {
|
||||
@@ -148,7 +144,7 @@ impl<W: Write> ratatui::backend::Backend for TermionBackendExt<W> {
|
||||
self.inner.clear_region(clear_type)
|
||||
}
|
||||
|
||||
fn size(&self) -> io::Result<Rect> {
|
||||
fn size(&self) -> io::Result<Size> {
|
||||
self.inner.size()
|
||||
}
|
||||
|
||||
|
||||
+63
-49
@@ -1,5 +1,5 @@
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::layout::{Position, Rect};
|
||||
use ratatui::style::Style;
|
||||
use ratatui::symbols;
|
||||
use ratatui::widgets::{BorderType, Borders, Widget};
|
||||
@@ -60,55 +60,63 @@ impl Widget for HeaderBlock {
|
||||
// Sides
|
||||
if self.borders.intersects(Borders::LEFT) {
|
||||
for y in area.top()..area.bottom() {
|
||||
buf.get_mut(area.left(), y)
|
||||
.set_symbol(symbols.vertical_left)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.left(), y)) {
|
||||
cell.set_symbol(symbols.vertical_left)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.borders.intersects(Borders::TOP) {
|
||||
for x in area.left()..area.right() {
|
||||
buf.get_mut(x, area.top())
|
||||
.set_symbol(symbols.horizontal_top)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(x, area.top())) {
|
||||
cell.set_symbol(symbols.horizontal_top)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.borders.intersects(Borders::RIGHT) {
|
||||
let x = area.right() - 1;
|
||||
for y in area.top()..area.bottom() {
|
||||
buf.get_mut(x, y)
|
||||
.set_symbol(symbols.vertical_right)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(x, y)) {
|
||||
cell.set_symbol(symbols.vertical_right)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.borders.intersects(Borders::BOTTOM) {
|
||||
let y = area.bottom() - 1;
|
||||
for x in area.left()..area.right() {
|
||||
buf.get_mut(x, y)
|
||||
.set_symbol(symbols.horizontal_bottom)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(x, y)) {
|
||||
cell.set_symbol(symbols.horizontal_bottom)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Corners
|
||||
if self.borders.contains(Borders::RIGHT | Borders::BOTTOM) {
|
||||
buf.get_mut(area.right() - 1, area.bottom() - 1)
|
||||
.set_symbol(symbols::line::VERTICAL_LEFT)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.right() - 1, area.bottom() - 1)) {
|
||||
cell.set_symbol(symbols::line::VERTICAL_LEFT)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
if self.borders.contains(Borders::RIGHT | Borders::TOP) {
|
||||
buf.get_mut(area.right() - 1, area.top())
|
||||
.set_symbol(symbols.top_right)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.right() - 1, area.top())) {
|
||||
cell.set_symbol(symbols.top_right)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
if self.borders.contains(Borders::LEFT | Borders::BOTTOM) {
|
||||
buf.get_mut(area.left(), area.bottom() - 1)
|
||||
.set_symbol(symbols::line::VERTICAL_RIGHT)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.left(), area.bottom() - 1)) {
|
||||
cell.set_symbol(symbols::line::VERTICAL_RIGHT)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
if self.borders.contains(Borders::LEFT | Borders::TOP) {
|
||||
buf.get_mut(area.left(), area.top())
|
||||
.set_symbol(symbols.top_left)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.left(), area.top())) {
|
||||
cell.set_symbol(symbols.top_left)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,32 +205,36 @@ impl Widget for FooterBlock {
|
||||
// Sides
|
||||
if self.borders.intersects(Borders::LEFT) {
|
||||
for y in area.top()..area.bottom() {
|
||||
buf.get_mut(area.left(), y)
|
||||
.set_symbol(symbols.vertical_left)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.left(), y)) {
|
||||
cell.set_symbol(symbols.vertical_left)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.borders.intersects(Borders::TOP) {
|
||||
for x in area.left()..area.right() {
|
||||
buf.get_mut(x, area.top())
|
||||
.set_symbol(symbols.horizontal_top)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(x, area.top())) {
|
||||
cell.set_symbol(symbols.horizontal_top)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.borders.intersects(Borders::RIGHT) {
|
||||
let x = area.right() - 1;
|
||||
for y in area.top()..area.bottom() {
|
||||
buf.get_mut(x, y)
|
||||
.set_symbol(symbols.vertical_right)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(x, y)) {
|
||||
cell.set_symbol(symbols.vertical_right)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.borders.intersects(Borders::BOTTOM) {
|
||||
let y = area.bottom() - 1;
|
||||
for x in area.left()..area.right() {
|
||||
buf.get_mut(x, y)
|
||||
.set_symbol(symbols.horizontal_bottom)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(x, y)) {
|
||||
cell.set_symbol(symbols.horizontal_bottom)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,28 +244,30 @@ impl Widget for FooterBlock {
|
||||
FooterBlockType::Begin | FooterBlockType::Repeat => symbols::line::HORIZONTAL_UP,
|
||||
_ => symbols.bottom_right,
|
||||
};
|
||||
buf.get_mut(area.right() - 1, area.bottom() - 1)
|
||||
.set_symbol(symbol)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.right() - 1, area.bottom() - 1)) {
|
||||
cell.set_symbol(symbol).set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
if self.borders.contains(Borders::RIGHT | Borders::TOP) {
|
||||
let symbol = match self.block_type {
|
||||
FooterBlockType::Begin | FooterBlockType::Repeat => symbols::line::HORIZONTAL_DOWN,
|
||||
_ => symbols::line::VERTICAL_LEFT,
|
||||
};
|
||||
buf.get_mut(area.right() - 1, area.top())
|
||||
.set_symbol(symbol)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.right() - 1, area.top())) {
|
||||
cell.set_symbol(symbol).set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
if self.borders.contains(Borders::LEFT | Borders::BOTTOM) {
|
||||
buf.get_mut(area.left(), area.bottom() - 1)
|
||||
.set_symbol(symbols.bottom_left)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.left(), area.bottom() - 1)) {
|
||||
cell.set_symbol(symbols.bottom_left)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
if self.borders.contains(Borders::LEFT | Borders::TOP) {
|
||||
buf.get_mut(area.left(), area.top())
|
||||
.set_symbol(symbols::line::VERTICAL_RIGHT)
|
||||
.set_style(self.border_style);
|
||||
if let Some(cell) = buf.cell_mut(Position::new(area.left(), area.top())) {
|
||||
cell.set_symbol(symbols::line::VERTICAL_RIGHT)
|
||||
.set_style(self.border_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ impl Frontend {
|
||||
}
|
||||
}
|
||||
terminal.draw(|frame| {
|
||||
let ctx = ctx.clone().with_frame_size(frame.size());
|
||||
let ctx = ctx.clone().with_frame_size(frame.area());
|
||||
|
||||
if let Err(err) = state.show(&ctx, frame) {
|
||||
log::warn!("Drawing failed: {}", err);
|
||||
|
||||
+5
-3
@@ -453,7 +453,7 @@ where
|
||||
.rows(rows)
|
||||
.widths(widths)
|
||||
.column_spacing(1)
|
||||
.highlight_style(style::highlight(area_focus));
|
||||
.row_highlight_style(style::highlight(area_focus));
|
||||
|
||||
let table = if !area_focus && self.dim {
|
||||
table.dim()
|
||||
@@ -1051,7 +1051,8 @@ impl<'a> TextEdit<'a> {
|
||||
frame.render_widget(overline, layout[1]);
|
||||
|
||||
if self.show_cursor {
|
||||
frame.set_cursor(top_layout[2].x + cursor_pos, top_layout[2].y)
|
||||
let position = Position::new(top_layout[2].x + cursor_pos, top_layout[2].y);
|
||||
frame.set_cursor_position(position)
|
||||
}
|
||||
} else {
|
||||
let top = Line::from([input].to_vec());
|
||||
@@ -1061,7 +1062,8 @@ impl<'a> TextEdit<'a> {
|
||||
frame.render_widget(bottom, layout[1]);
|
||||
|
||||
if self.show_cursor {
|
||||
frame.set_cursor(area.x + cursor_pos, area.y)
|
||||
let position = Position::new(area.x + cursor_pos, area.y);
|
||||
frame.set_cursor_position(position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ impl Frontend {
|
||||
break Ok(interrupted);
|
||||
}
|
||||
}
|
||||
terminal.draw(|frame| root.render(RenderProps::from(frame.size()), frame))?;
|
||||
terminal.draw(|frame| root.render(RenderProps::from(frame.area()), frame))?;
|
||||
};
|
||||
terminal.restore()?;
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
use termion::event::Key;
|
||||
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Position, Rect};
|
||||
use ratatui::style::{Style, Stylize};
|
||||
use ratatui::text::{Line, Span, Text};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::ui::theme::Theme;
|
||||
|
||||
@@ -287,7 +287,10 @@ where
|
||||
frame.render_widget(overline, layout[1]);
|
||||
|
||||
if props.show_cursor {
|
||||
frame.set_cursor(top_layout[2].x + cursor_pos, top_layout[2].y)
|
||||
frame.set_cursor_position(Position::new(
|
||||
top_layout[2].x + cursor_pos,
|
||||
top_layout[2].y,
|
||||
))
|
||||
}
|
||||
} else {
|
||||
let top = Line::from([input].to_vec());
|
||||
@@ -297,7 +300,7 @@ where
|
||||
frame.render_widget(bottom, layout[1]);
|
||||
|
||||
if props.show_cursor {
|
||||
frame.set_cursor(area.x + cursor_pos, area.y)
|
||||
frame.set_cursor_position(Position::new(area.x + cursor_pos, area.y))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -516,7 +519,7 @@ impl<'a, S, M> View for TextArea<'a, S, M> {
|
||||
(self.textarea.cursor().0, self.textarea.cursor().1),
|
||||
);
|
||||
|
||||
frame.render_widget(self.textarea.widget(), content_area);
|
||||
frame.render_widget(&self.textarea, content_area);
|
||||
|
||||
let mut progress_info = vec![];
|
||||
|
||||
|
||||
@@ -272,7 +272,7 @@ where
|
||||
.rows(rows)
|
||||
.widths(widths)
|
||||
.column_spacing(1)
|
||||
.highlight_style(style::highlight(render.focus));
|
||||
.row_highlight_style(style::highlight(render.focus));
|
||||
|
||||
let table = if !render.focus && props.dim {
|
||||
table.dim()
|
||||
|
||||
@@ -104,7 +104,7 @@ where
|
||||
.and_then(|props| props.inner_ref::<WindowProps<Id>>())
|
||||
.unwrap_or(&default);
|
||||
|
||||
let area = frame.size();
|
||||
let area = frame.area();
|
||||
|
||||
let page = props
|
||||
.current_page
|
||||
|
||||
Reference in New Issue
Block a user