Skip to content

Commit 44e4e9b

Browse files
committed
feat: highlight address in code and data
1 parent 6bd421f commit 44e4e9b

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/tui/code.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,38 +229,43 @@ impl Component for Code {
229229
.take(self.frame.size.height)
230230
.enumerate()
231231
{
232-
let mut style = if ins.ip32() == self.props.addr.offset {
233-
super::ST_ACTIVE
232+
let (mut addr_st, mut code_st) = if ins.ip32() == self.props.addr.offset {
233+
(super::ST_ACTIVE, super::ST_ACTIVE)
234234
} else {
235-
super::ST_NORMAL
235+
(super::ST_CAPTION, super::ST_NORMAL)
236236
};
237237

238238
if self.props.status.attached && self.pos == Some(y) {
239-
style.background = super::ST_SELECTED.background;
239+
addr_st.background = super::ST_SELECTED.background;
240+
code_st.background = super::ST_SELECTED.background;
240241

241242
canvas.clear_region(
242243
Rect::new(Position::new(0, y), Size::new(self.frame.size.width, 1)),
243-
style,
244+
code_st,
244245
);
245246
}
246247

247-
canvas.draw_str(0, y, style, &format!("{:04X}", self.props.addr.segment));
248-
canvas.draw_str(6, y, style, &format!("{:04X}", ins.ip16()));
248+
canvas.draw_str(
249+
0,
250+
y,
251+
addr_st,
252+
&format!("{:04X}:{:04X}", self.props.addr.segment, ins.ip16()),
253+
);
249254
canvas.draw_str(
250255
12,
251256
y,
252-
style,
257+
code_st,
253258
&data.iter().fold(String::new(), |a, x| format!("{a}{x:02X}")),
254259
);
255260

256261
out.clear();
257262
fmt.format_mnemonic(ins, &mut out);
258-
canvas.draw_str(30, y, style, &out);
263+
canvas.draw_str(30, y, code_st, &out);
259264

260265
if ins.op_count() > 0 {
261266
out.clear();
262267
fmt.format_all_operands(ins, &mut out);
263-
canvas.draw_str(42, y, style, &out);
268+
canvas.draw_str(42, y, code_st, &out);
264269
}
265270
}
266271

src/tui/data.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,34 +206,39 @@ impl Component for Data {
206206
canvas.clear(super::ST_NORMAL);
207207

208208
for (y, bytes) in self.data.chunks(BYTES_PER_LINE).skip(self.skip).enumerate() {
209-
let mut style = super::ST_NORMAL;
209+
let mut addr_st = super::ST_CAPTION;
210+
let mut data_st = super::ST_NORMAL;
210211

211212
if self.pos == Some(y) {
212-
style.background = super::ST_SELECTED.background;
213+
addr_st.background = super::ST_SELECTED.background;
214+
data_st.background = super::ST_SELECTED.background;
213215

214216
canvas.clear_region(
215217
Rect::new(Position::new(0, y), Size::new(self.frame.size.width, 1)),
216-
style,
218+
data_st,
217219
);
218220
}
219221

220-
canvas.draw_str(0, y, style, &format!("{:04X}", self.addr.segment));
221222
canvas.draw_str(
222-
6,
223+
0,
223224
y,
224-
style,
225-
&format!("{:04X}", self.addr.offset as usize + (y + self.skip) * BYTES_PER_LINE),
225+
addr_st,
226+
&format!(
227+
"{:04X}:{:04X}",
228+
self.addr.segment,
229+
self.addr.offset as usize + (y + self.skip) * BYTES_PER_LINE
230+
),
226231
);
227232
canvas.draw_str(
228233
12,
229234
y,
230-
style,
235+
data_st,
231236
&bytes.iter().fold(String::new(), |a, x| format!("{a}{x:02X} ")),
232237
);
233238
canvas.draw_str(
234-
61,
239+
62,
235240
y,
236-
style,
241+
data_st,
237242
&bytes.iter().fold(String::new(), |a, x| {
238243
let c = char::from(*x);
239244
format!("{a}{}", if matches!(*x, 32..=0x7E) { c } else { NON_ASCII_CHAR })

0 commit comments

Comments
 (0)