diff --git a/Cargo.lock b/Cargo.lock index cfef1a3..8f59f58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,6 +70,17 @@ dependencies = [ "libc", ] +[[package]] +name = "ansi-to-tui" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b0e348dcd256ba06d44d5deabc88a7c0e80ee7303158253ca069bcd9e9b7f57" +dependencies = [ + "nom", + "ratatui", + "thiserror", +] + [[package]] name = "anstream" version = "0.6.4" @@ -624,6 +635,7 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" name = "doggy" version = "0.4.2" dependencies = [ + "ansi-to-tui", "better-panic", "bollard", "chrono", diff --git a/Cargo.toml b/Cargo.toml index d1000f6..27f202c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ log4rs = "1.2.0" pretty_assertions = "1.4.0" ratatui = { version = "0.25.0", features = ["serde", "macros", "unstable-rendered-line-info"] } +ansi-to-tui = { version = "3.1.0" } serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" diff --git a/doc/scripts/docker-compose.yaml b/doc/scripts/docker-compose.yaml index 1cb51db..6637ed5 100644 --- a/doc/scripts/docker-compose.yaml +++ b/doc/scripts/docker-compose.yaml @@ -10,3 +10,12 @@ services: - bash - -c - apt update && apt install -y curl && while true; do sleep 1; curl whoami/api; done + lolcat: + image: ubuntu:22.04 + command: + - bash + - -c + - apt update && apt install -y lolcat && while true; do sleep 1; date | /usr/games/lolcat; done + tty: true + environment: + TERM: xterm-256color diff --git a/src/components/container_logs.rs b/src/components/container_logs.rs index 31e4ce1..8010318 100644 --- a/src/components/container_logs.rs +++ b/src/components/container_logs.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use ansi_to_tui::IntoText; use bollard::container::LogsOptions; use chrono::{Duration, Utc}; use color_eyre::Result; @@ -219,24 +220,16 @@ impl ContainerLogs { ), ])) .block(Block::default().borders(Borders::NONE).gray()); - let mut log_paragraph = Paragraph::new( - logs.iter() - .map(|l| Line::from(Span::from(l))) - .collect::>(), - ) - .block( - Block::default() - .borders(Borders::ALL) - .gray() - .title(Span::styled( - format!( + let text = logs.join("").into_text().expect("Cannot parse logs"); + let mut log_paragraph = + Paragraph::new(text).block(Block::default().borders(Borders::ALL).title(Span::styled( + format!( "Container logs for: \"{}/{}\" (press 'ESC' to previous screen, 'q' to quit)", &self.id[0..12], self.name ), - Style::default().add_modifier(Modifier::BOLD), - )), - ); + Style::default().add_modifier(Modifier::BOLD), + ))); if self.line_wrap { log_paragraph = log_paragraph.wrap(Wrap { trim: false }); }