summaryrefslogtreecommitdiff
path: root/src/registers.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2023-10-16 19:59:57 +0200
committerSanto Cariotti <santo@dcariotti.me>2023-10-16 19:59:57 +0200
commit74c390ef4deea9b042f55a4cfef5d1668408a2c2 (patch)
treecae6cfa09e32ed48a257055d4964a0df32527017 /src/registers.rs
parentd5948b5ace52c8d3970ca14b9354acf06eb6456f (diff)
Show date on each line
Diffstat (limited to 'src/registers.rs')
-rw-r--r--src/registers.rs23
1 files changed, 15 insertions, 8 deletions
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<Local>,
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
+ )),
])
}
}