tui: bring the transcript closer to display mode (#4848)

before
<img width="1161" height="836" alt="Screenshot 2025-10-06 at 3 06 52 PM"
src="https://github.com/user-attachments/assets/7622fd6b-9d37-402f-8651-61c2c55dcbc6"
/>

after
<img width="1161" height="858" alt="Screenshot 2025-10-06 at 3 07 02 PM"
src="https://github.com/user-attachments/assets/1498f327-1d1a-4630-951f-7ca371ab0139"
/>
This commit is contained in:
Jeremy Rose
2025-10-07 16:18:48 -07:00
committed by GitHub
parent 60f9e85c16
commit 0e5d72cc57
13 changed files with 233 additions and 187 deletions

View File

@@ -38,11 +38,13 @@ pub trait RectExt {
impl RectExt for Rect {
fn inset(&self, insets: Insets) -> Rect {
let horizontal = insets.left.saturating_add(insets.right);
let vertical = insets.top.saturating_add(insets.bottom);
Rect {
x: self.x + insets.left,
y: self.y + insets.top,
width: self.width - insets.left - insets.right,
height: self.height - insets.top - insets.bottom,
x: self.x.saturating_add(insets.left),
y: self.y.saturating_add(insets.top),
width: self.width.saturating_sub(horizontal),
height: self.height.saturating_sub(vertical),
}
}
}

View File

@@ -1,3 +1,5 @@
use std::sync::Arc;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::text::Line;
@@ -12,6 +14,12 @@ pub trait Renderable {
fn desired_height(&self, width: u16) -> u16;
}
impl<R: Renderable + 'static> From<R> for Box<dyn Renderable> {
fn from(value: R) -> Self {
Box::new(value)
}
}
impl Renderable for () {
fn render(&self, _area: Rect, _buf: &mut Buffer) {}
fn desired_height(&self, _width: u16) -> u16 {
@@ -71,6 +79,15 @@ impl<R: Renderable> Renderable for Option<R> {
}
}
impl<R: Renderable> Renderable for Arc<R> {
fn render(&self, area: Rect, buf: &mut Buffer) {
self.as_ref().render(area, buf);
}
fn desired_height(&self, width: u16) -> u16 {
self.as_ref().desired_height(width)
}
}
pub struct ColumnRenderable {
children: Vec<Box<dyn Renderable>>,
}
@@ -122,7 +139,10 @@ impl Renderable for InsetRenderable {
}
impl InsetRenderable {
pub fn new(child: Box<dyn Renderable>, insets: Insets) -> Self {
Self { child, insets }
pub fn new(child: impl Into<Box<dyn Renderable>>, insets: Insets) -> Self {
Self {
child: child.into(),
insets,
}
}
}