From 74c390ef4deea9b042f55a4cfef5d1668408a2c2 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 16 Oct 2023 19:59:57 +0200 Subject: Show date on each line --- src/registers.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/registers.rs') diff --git a/src/registers.rs b/src/registers.rs index cf2aa98..0fc4296 100644 --- a/src/registers.rs +++ b/src/registers.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, Local}; use nix::libc::user_regs_struct; use owo_colors::OwoColorize; use ratatui::{ @@ -8,6 +9,7 @@ use ratatui::{ /// Struct used to manipulate registers data from https://docs.rs/libc/0.2.147/libc/struct.user_regs_struct.html #[derive(Debug)] pub struct RegistersData { + timestamp: DateTime, orig_rax: u64, rdi: u64, rsi: u64, @@ -19,6 +21,7 @@ impl RegistersData { /// Create new `RegistersData` from an `user_regs_struct`'C structure pub fn new(registers: user_regs_struct) -> RegistersData { RegistersData { + timestamp: Local::now(), orig_rax: registers.orig_rax, rdi: registers.rdi, rsi: registers.rsi, @@ -27,10 +30,16 @@ impl RegistersData { } } + /// Get date in ISO 8601 / RFC 3339 date & time string format + pub fn date(&self) -> String { + self.timestamp.format("%+").to_string() + } + /// Returns a good string which shows the output for a line pub fn output(&self) -> String { format!( - "{}({:x}, {:x}, {:x}, ...) = {:x}", + "[{}]: {}({:x}, {:x}, {:x}, ...) = {:x}", + self.date(), self.orig_rax.bold(), self.rdi, self.rsi, @@ -42,17 +51,15 @@ impl RegistersData { /// Returns a good line for TUI pub fn output_ui(&self) -> Line { Line::from(vec![ + Span::raw(format!("[{}]: ", self.date())), Span::styled( format!("{}", self.orig_rax), Style::default().add_modifier(Modifier::BOLD), ), - Span::styled( - format!( - "({:x}, {:x}, {:x}, ...) = {:x}", - self.rdi, self.rsi, self.rdx, self.rax - ), - Style::default(), - ), + Span::raw(format!( + "({:x}, {:x}, {:x}, ...) = {:x}", + self.rdi, self.rsi, self.rdx, self.rax + )), ]) } } -- cgit v1.2.3-18-g5258