Skip to content

Commit

Permalink
✨ add colored log output (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyaillet authored Jan 21, 2024
1 parent 26b2336 commit 7ed4ee5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions doc/scripts/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 7 additions & 14 deletions src/components/container_logs.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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::<Vec<Line>>(),
)
.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 });
}
Expand Down

0 comments on commit 7ed4ee5

Please sign in to comment.