First commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
style::Stylize,
|
||||
symbols::border,
|
||||
text::{Line, Text},
|
||||
widgets::{Block, Paragraph, Widget},
|
||||
};
|
||||
|
||||
use crate::binary_repr::BinaryRepr;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Hexadecimal {
|
||||
repr: BinaryRepr,
|
||||
}
|
||||
|
||||
impl Hexadecimal {
|
||||
pub fn update(&mut self, input: &BinaryRepr) {
|
||||
self.repr = input.clone();
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for &Hexadecimal {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let mut out = Line::from("0x".to_owned().gray());
|
||||
let binding = self.repr.to_hex();
|
||||
let mut txt = binding.as_str();
|
||||
let mut color = false;
|
||||
for _ in 0..txt.len().div_ceil(2) {
|
||||
if color {
|
||||
out += txt[0..2.min(txt.len())].cyan();
|
||||
} else {
|
||||
out += txt[0..2.min(txt.len())].red();
|
||||
}
|
||||
txt = &txt[2.min(txt.len())..];
|
||||
color = !color;
|
||||
}
|
||||
|
||||
let input_block = Block::bordered()
|
||||
.title(Line::from("hexadecimal".bold()))
|
||||
.border_set(border::PLAIN);
|
||||
|
||||
Paragraph::new(out).block(input_block).render(area, buf);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user