From 142169ee42c6db57cab8d51a01b2decfb96384f2 Mon Sep 17 00:00:00 2001 From: veeso Date: Sat, 27 Mar 2021 14:59:46 +0100 Subject: [PATCH] Fixed logbox multi-lines not working properly; fixed exec command format --- .../filetransfer_activity/actions.rs | 4 +-- .../filetransfer_activity/update.rs | 7 +++-- src/ui/layout/components/logbox.rs | 28 ++++++++++++++----- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/ui/activities/filetransfer_activity/actions.rs b/src/ui/activities/filetransfer_activity/actions.rs index bc6a435..ebbb778 100644 --- a/src/ui/activities/filetransfer_activity/actions.rs +++ b/src/ui/activities/filetransfer_activity/actions.rs @@ -449,7 +449,7 @@ impl FileTransferActivity { // Reload files self.log( LogLevel::Info, - format!("\"{}\" output: \"{}\"", input, output).as_ref(), + format!("\"{}\": {}", input, output).as_ref(), ); let wrkdir: PathBuf = self.local.wrkdir.clone(); self.local_scan(wrkdir.as_path()); @@ -470,7 +470,7 @@ impl FileTransferActivity { // Reload files self.log( LogLevel::Info, - format!("\"{}\" output: \"{}\"", input, output).as_ref(), + format!("\"{}\": {}", input, output).as_ref(), ); self.reload_remote_dir(); } diff --git a/src/ui/activities/filetransfer_activity/update.rs b/src/ui/activities/filetransfer_activity/update.rs index 50472d0..62e971a 100644 --- a/src/ui/activities/filetransfer_activity/update.rs +++ b/src/ui/activities/filetransfer_activity/update.rs @@ -827,8 +827,9 @@ impl FileTransferActivity { // Make log entries let mut table: TableBuilder = TableBuilder::default(); for (idx, record) in self.log_records.iter().enumerate() { - let record_rows = textwrap::wrap(record.msg.as_str(), (width as usize) - 38); // -35 'cause log prefix -3 cause of log line cursor - // Add row if not first row + // Split rows by width NOTE: -37 'cause log prefix -3 cause of log line cursor + let record_rows = textwrap::wrap(record.msg.as_str(), (width as usize) - 40); + // Add row if not first row if idx > 0 { table.add_row(); } @@ -868,7 +869,7 @@ impl FileTransferActivity { _ => { table.add_col(TextSpan::from(textwrap::indent( row.as_ref(), - " ", + " ", ))); } } diff --git a/src/ui/layout/components/logbox.rs b/src/ui/layout/components/logbox.rs index bd8d9a8..90a395b 100644 --- a/src/ui/layout/components/logbox.rs +++ b/src/ui/layout/components/logbox.rs @@ -29,6 +29,7 @@ use super::{Canvas, Component, InputEvent, Msg, Payload, Props, PropsBuilder}; // ext use crossterm::event::KeyCode; +use std::collections::VecDeque; use tui::{ layout::{Corner, Rect}, style::Style, @@ -145,7 +146,7 @@ impl Component for LogBox { .iter() .enumerate() .map(|(idx, row)| { - let mut columns: Vec = row + let mut columns: VecDeque = row .iter() .map(|col| { Span::styled( @@ -157,9 +158,10 @@ impl Component for LogBox { ) }) .collect(); - let mut row: Vec = Vec::with_capacity(columns.len() + 1); - // Push green cursor if selected line - row.push(Span::styled( + // Let's convert column spans into Spans rows NOTE: -4 because first line is always made by 5 columns; but there's always 1 + let mut rows: Vec = Vec::with_capacity(columns.len() - 4); + // Get first row + let mut first_row: Vec = vec![Span::styled( match self.states.list_index == idx { true => "> ", false => " ", @@ -167,9 +169,21 @@ impl Component for LogBox { Style::default() .fg(self.props.foreground) .bg(self.props.background), - )); - row.append(&mut columns); - ListItem::new(Spans::from(row)) + )]; + for _ in 0..5 { + if let Some(col) = columns.pop_front() { + first_row.push(col); + } + } + rows.push(Spans::from(first_row)); + // Fill remaining rows + let cycles: usize = columns.len(); + for _ in 0..cycles { + if let Some(col) = columns.pop_front() { + rows.push(Spans::from(vec![col])); + } + } + ListItem::new(rows) }) .collect(), // Make List item from TextSpan };