Skip to content

Commit

Permalink
feat: chunking error text to multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed May 27, 2024
1 parent 10b8d8a commit 8a4b8f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion tui/src/pages/collection_viewer/collection_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions tui/src/pages/collection_viewer/res_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
.chunks(self.layout.content_pane.width.sub(3).into())
.map(|chunk| {
Line::from(chunk.iter().collect::<String>().fg(self.colors.normal.red))
})
.collect::<Vec<_>>(),
)
.collect::<Vec<Line>>(),
)
};
Expand Down Expand Up @@ -225,15 +235,14 @@ 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,
);

Paragraph::new(self.error_lines.clone().unwrap())
.fg(self.colors.bright.black)
.centered()
.render(size, buf);
}
}
Expand Down
9 changes: 3 additions & 6 deletions tui/src/pages/spinner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::ops::Add;

use rand::Rng;
use ratatui::{
buffer::Buffer,
Expand All @@ -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,
Expand Down Expand Up @@ -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<S>(self, label: S) -> Self
where
S: Into<Span<'static>>,
Expand Down

0 comments on commit 8a4b8f4

Please sign in to comment.