From 1aaf59f036e924d038722fb64c72ff7df3331bac Mon Sep 17 00:00:00 2001 From: Jaby Blubb Date: Sun, 20 Aug 2023 17:32:10 +0200 Subject: [PATCH] Color encode OVERLAPPED sections and set version to 1.0 --- src/Tools/psxreadmap/Cargo.toml | 2 +- src/Tools/psxreadmap/src/lib.rs | 69 ++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/Tools/psxreadmap/Cargo.toml b/src/Tools/psxreadmap/Cargo.toml index e57d7caa..f3b95e30 100644 --- a/src/Tools/psxreadmap/Cargo.toml +++ b/src/Tools/psxreadmap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "psxreadmap" -version = "0.1.0" +version = "1.0.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/Tools/psxreadmap/src/lib.rs b/src/Tools/psxreadmap/src/lib.rs index 95577ff8..f0e70241 100644 --- a/src/Tools/psxreadmap/src/lib.rs +++ b/src/Tools/psxreadmap/src/lib.rs @@ -413,10 +413,15 @@ impl ConsoleUI { let section_list = List::new(data.section_info.iter().map( |section| { - ListItem::new(section.name.clone()) + let mut new_item = ListItem::new(section.name.clone()); + + if let Some(color) = section.color_share { + new_item = new_item.style(Style::default().fg(color)); + } + new_item }).collect::>()).style(Style::default().fg(Color::White)) .block(Self::create_default_border("Section")) - .highlight_style(Style::default().bg(Color::White)); + .highlight_style(Style::default().add_modifier(Modifier::REVERSED|Modifier::BOLD)); let top_section = Self::get_selected_top_section(section_selection, data); let mut info_data: &dyn NamedMemoryArea = top_section; @@ -522,6 +527,7 @@ impl ConsoleUIData { pub const RAM_SIZE:usize = 2*1024*1024; pub fn from(memory_map: MemoryMap) -> Result { + const COLORS:[Color;4] = [Color::Red, Color::Green, Color::Blue, Color::Yellow]; fn get_last_section_end_adr(memory_map: &MemoryMap) -> u64 { if let Some(section) = memory_map.sections.last() { return section.adr + section.size as u64; @@ -530,38 +536,65 @@ impl ConsoleUIData { } let mut new_self = ConsoleUIData::default(); + let mut color_idx = 0; let highest_adr = get_last_section_end_adr(&memory_map); let program_size = (highest_adr - Self::RAM_BASE_ADDRESS) as usize; new_self.section_info.push(SectionInfo{ - name: String::from(""), - symbols: memory_map.global, - start_adr: Self::RAM_BASE_ADDRESS, - size: program_size, - max_size: Self::RAM_SIZE + name: String::from(""), + symbols: memory_map.global, + start_adr: Self::RAM_BASE_ADDRESS, + size: program_size, + max_size: Self::RAM_SIZE, + color_share: None, }); for section in memory_map.sections { new_self.section_info.push(SectionInfo{ - name: section.name, - symbols: section.symbols, - start_adr: section.adr, - size: section.size, - max_size: program_size + name: section.name, + symbols: section.symbols, + start_adr: section.adr, + size: section.size, + max_size: program_size, + color_share: None, }); } + let mut iter = new_self.section_info.iter_mut().peekable(); + while let Some(section) = iter.next() { + if let Some(next_section) = iter.peek_mut() { + if section.start_adr == next_section.start_adr { + let color = { + if let Some(color) = section.color_share { + color + } + + else { + // next color + let color = COLORS[color_idx]; + + color_idx = (color_idx + 1)%COLORS.len(); + color + } + }; + + section.color_share = Some(color); + next_section.color_share = Some(color); + } + } + } + Ok(new_self) } } -#[derive(Default)] struct SectionInfo { - pub name: String, - pub symbols: Vec, - pub start_adr: u64, - pub size: usize, - pub max_size: usize, + pub name: String, + pub symbols: Vec, + pub start_adr: u64, + pub size: usize, + pub max_size: usize, + pub color_share: Option } impl SectionInfo {