yazi/yazi-widgets/src/input/widget.rs
2026-04-16 17:05:46 +08:00

30 lines
666 B
Rust

use std::ops::Range;
use ratatui::{layout::Rect, text::Line, widgets::Widget};
use yazi_config::THEME;
use super::Input;
impl Widget for &Input {
fn render(self, area: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer)
where
Self: Sized,
{
crate::Clear.render(area, buf);
Line::styled(self.display(), THEME.input.value.get()).render(area, buf);
if let Some(Range { start, end }) = self.selected() {
let s = start.min(area.width);
buf.set_style(
Rect {
x: area.x + s,
y: area.y,
width: (end - start).min(area.width - s),
height: area.height.min(1),
},
THEME.input.selected.get(),
);
}
}
}