From 8a4b8f4a9ed19a5ee00f4f9e0b02a59162bd06a1 Mon Sep 17 00:00:00 2001 From: Willians Faria Date: Mon, 27 May 2024 18:38:58 -0300 Subject: [PATCH] feat: chunking error text to multiline --- .../collection_viewer/collection_viewer.rs | 1 - tui/src/pages/collection_viewer/res_viewer.rs | 17 +++++++++++++---- tui/src/pages/spinner.rs | 9 +++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tui/src/pages/collection_viewer/collection_viewer.rs b/tui/src/pages/collection_viewer/collection_viewer.rs index 484769d..8217c1a 100644 --- a/tui/src/pages/collection_viewer/collection_viewer.rs +++ b/tui/src/pages/collection_viewer/collection_viewer.rs @@ -187,7 +187,6 @@ impl<'ae> CollectionViewer<'ae> { config, editor: ReqEditor::new(colors, selected_request.clone(), layout.req_editor, config), - res_viewer: ResViewer::new(colors, None, layout.response_preview), hovered_request, diff --git a/tui/src/pages/collection_viewer/res_viewer.rs b/tui/src/pages/collection_viewer/res_viewer.rs index 781939d..a18c252 100644 --- a/tui/src/pages/collection_viewer/res_viewer.rs +++ b/tui/src/pages/collection_viewer/res_viewer.rs @@ -156,8 +156,18 @@ impl<'a> ResViewer<'a> { &mut rand::thread_rng(), ) .iter() - .map(|line| line.to_string().into()) - .chain(vec!["".into(), cause.fg(self.colors.normal.red).into()]) + .map(|line| Line::from(line.to_string()).centered()) + .chain(vec!["".into()]) + .chain( + cause + .chars() + .collect::>() + .chunks(self.layout.content_pane.width.sub(3).into()) + .map(|chunk| { + Line::from(chunk.iter().collect::().fg(self.colors.normal.red)) + }) + .collect::>(), + ) .collect::>(), ) }; @@ -225,7 +235,7 @@ impl<'a> ResViewer<'a> { .sub(self.error_lines.as_ref().unwrap().len().div_ceil(2) as u16); let size = Rect::new( - request_pane.x, + request_pane.x.add(1), center, request_pane.width, self.error_lines.as_ref().unwrap().len() as u16, @@ -233,7 +243,6 @@ impl<'a> ResViewer<'a> { Paragraph::new(self.error_lines.clone().unwrap()) .fg(self.colors.bright.black) - .centered() .render(size, buf); } } diff --git a/tui/src/pages/spinner.rs b/tui/src/pages/spinner.rs index 3647e0a..c8780c8 100644 --- a/tui/src/pages/spinner.rs +++ b/tui/src/pages/spinner.rs @@ -1,5 +1,3 @@ -use std::ops::Add; - use rand::Rng; use ratatui::{ buffer::Buffer, @@ -8,11 +6,8 @@ use ratatui::{ text::{Line, Span}, widgets::Widget, }; +use std::ops::Add; -/// Renders a spinning widget to the screen. -/// -/// Can either be used as a StatefulWidget which will allow fine grained control, -/// or used as a Widget, which will render a random symbol that updates #[derive(Debug, Clone)] pub struct Spinner { step: usize, @@ -54,6 +49,8 @@ impl Spinner { } } + /// adds a label to the spinner, which will be displayed at the right + /// to the pub fn with_label(self, label: S) -> Self where S: Into>,