Implement long task description wraping

If task description is longer than window width -> wrap rest
This commit is contained in:
三咲雅 · Misaki Masa 2025-01-22 22:00:45 +08:00 committed by Viktor Karpilov
parent abb43251fa
commit 6ce62761a8
3 changed files with 42 additions and 3 deletions

24
Cargo.lock generated
View file

@ -2394,6 +2394,12 @@ version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "smawk"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
[[package]]
name = "socket2"
version = "0.5.8"
@ -2506,6 +2512,17 @@ version = "0.12.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
[[package]]
name = "textwrap"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9"
dependencies = [
"smawk",
"unicode-linebreak",
"unicode-width 0.1.14",
]
[[package]]
name = "thiserror"
version = "1.0.69"
@ -2824,6 +2841,12 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "unicode-linebreak"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-segmentation"
version = "1.12.0"
@ -3459,6 +3482,7 @@ dependencies = [
"scopeguard",
"signal-hook-tokio",
"syntect",
"textwrap",
"tikv-jemallocator",
"tokio",
"tokio-stream",

View file

@ -42,6 +42,7 @@ tokio-stream = { workspace = true }
tracing = { workspace = true }
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.19", features = [ "env-filter" ] }
textwrap = "0.16.1"
[target."cfg(unix)".dependencies]
libc = { workspace = true }

View file

@ -1,4 +1,10 @@
use ratatui::{buffer::Buffer, layout::{self, Alignment, Constraint, Rect}, text::Line, widgets::{Block, BorderType, List, ListItem, Padding, Widget}};
use ratatui::{
buffer::Buffer,
layout::{self, Alignment, Constraint, Rect},
text::{Line, Text},
widgets::{Block, BorderType, List, Padding, Widget},
};
use textwrap::Options;
use yazi_config::THEME;
use yazi_core::tasks::TASKS_PERCENT;
@ -9,7 +15,9 @@ pub(crate) struct Tasks<'a> {
}
impl<'a> Tasks<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }
pub(crate) fn new(cx: &'a Ctx) -> Self {
Self { cx }
}
pub(super) fn area(area: Rect) -> Rect {
let chunk = layout::Layout::vertical([
@ -48,7 +56,13 @@ impl Widget for Tasks<'_> {
.take(area.height.saturating_sub(2) as usize)
.enumerate()
.map(|(i, v)| {
let mut item = ListItem::new(v.name.clone());
let line_otions = Options::new(area.width as usize).subsequent_indent(" ");
let lines = textwrap::wrap(&v.name, line_otions)
.iter()
.map(|s| Line::from(s.clone()))
.collect::<Vec<Line>>();
let mut item = Text::from(lines);
if i == tasks.cursor {
item = item.style(THEME.tasks.hovered);
}