Integrate all the progress into master #6
|
@ -71,20 +71,15 @@ impl ListSelection {
|
|||
}
|
||||
|
||||
pub fn decrement(&mut self, max: usize) {
|
||||
if let Some(cur_selection) = self.selection {
|
||||
if let Some(mut cur_selection) = self.selection {
|
||||
self.selection = Some({
|
||||
if cur_selection - 1 >= max {
|
||||
if max - 1 > 0 {
|
||||
cur_selection = cur_selection - 1;
|
||||
if cur_selection > max - 1 {
|
||||
max - 1
|
||||
}
|
||||
|
||||
else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
cur_selection - 1
|
||||
cur_selection
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -124,7 +119,7 @@ impl ConsoleUI {
|
|||
}
|
||||
|
||||
pub fn update_data(&mut self, memory_map: &MemoryMap) -> Result<(), Error> {
|
||||
self.data.update(memory_map)?;
|
||||
self.data = ConsoleUIData::from(memory_map)?;
|
||||
|
||||
if self.data.list.len() > 0 {
|
||||
if !self.content_selection.is_active() {
|
||||
|
@ -273,7 +268,7 @@ impl ConsoleUI {
|
|||
)
|
||||
.highlight_style(Style::default().bg(Color::Cyan));
|
||||
let first_mem_gauge = Self::create_mem_gauge("Overall memory usage", data.highest_adr, Color::Cyan);
|
||||
let second_mem_gauge = Self::create_mem_gauge("Overall memory usage", data.highest_adr, Color::Red);
|
||||
let second_mem_gauge = Self::create_mem_gauge_from(&data.overall_info, Color::Red);
|
||||
let mut list_state = ListState::default();
|
||||
|
||||
list_state.select(content_selection.selection);
|
||||
|
@ -295,6 +290,15 @@ impl ConsoleUI {
|
|||
.ratio(adr_ratio).label(format!("{}%", adr_ratio*100.0f64))
|
||||
}
|
||||
|
||||
fn create_mem_gauge_from<'a>(section_info: &SectionInfo, color: Color) -> Gauge<'a> {
|
||||
let adr_ratio = section_info.get_size_ratio();
|
||||
Gauge::default().block(Block::default().borders(Borders::ALL)
|
||||
.title(format!("{} @0x{:x} - 0x{:x} [{}b/{}b]",
|
||||
section_info.name, section_info.start_adr, section_info.get_end_adr(), section_info.size, section_info.max_size)))
|
||||
.gauge_style(Style::default().fg(color).bg(Color::Black).add_modifier(Modifier::BOLD))
|
||||
.ratio(adr_ratio).label(format!("{}%", adr_ratio*100.0f64))
|
||||
}
|
||||
|
||||
fn create_exit_message<'a>() -> Paragraph<'a> {
|
||||
Paragraph::new("Press \"ENTER\" to exit")
|
||||
.style(Style::default().fg(Color::White))
|
||||
|
@ -309,22 +313,17 @@ impl ConsoleUI {
|
|||
|
||||
#[derive(Default)]
|
||||
struct ConsoleUIData {
|
||||
highest_adr: u64,
|
||||
list: Vec<String>
|
||||
highest_adr: u64,
|
||||
overall_info: SectionInfo,
|
||||
list: Vec<String>
|
||||
}
|
||||
|
||||
impl ConsoleUIData {
|
||||
pub const RAM_BASE_ADDRESS:u64 = 0x80000000;
|
||||
pub const HIGHEST_RAM_ADDRESS:u64 = Self::RAM_BASE_ADDRESS + (2*1024*1024);
|
||||
pub const RAM_SIZE:usize = 2*1024*1024;
|
||||
pub const HIGHEST_RAM_ADDRESS:u64 = Self::RAM_BASE_ADDRESS + Self::RAM_SIZE as u64;
|
||||
|
||||
fn _new(memory_map: &MemoryMap) -> Result<ConsoleUIData, Error> {
|
||||
let mut ui_data = ConsoleUIData::default();
|
||||
|
||||
ui_data.update(memory_map)?;
|
||||
Ok(ui_data)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, memory_map: &MemoryMap) -> Result<(), Error> {
|
||||
pub fn from(memory_map: &MemoryMap) -> Result<Self, Error> {
|
||||
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;
|
||||
|
@ -332,12 +331,41 @@ impl ConsoleUIData {
|
|||
0u64
|
||||
}
|
||||
|
||||
self.highest_adr = get_last_section_end_adr(memory_map);
|
||||
self.list = vec![String::from("<overall usage>")];
|
||||
let mut new_self = ConsoleUIData::default();
|
||||
|
||||
new_self.highest_adr = get_last_section_end_adr(memory_map);
|
||||
new_self.list = vec![String::from("<overall usage>")];
|
||||
for section in &memory_map.sections {
|
||||
self.list.push(section.name.clone());
|
||||
new_self.list.push(section.name.clone());
|
||||
}
|
||||
Ok(())
|
||||
|
||||
// Testing new data type
|
||||
new_self.overall_info = SectionInfo{
|
||||
name: "Schwimmflügel".to_string(),
|
||||
start_adr: Self::RAM_BASE_ADDRESS,
|
||||
size: (new_self.highest_adr - Self::RAM_BASE_ADDRESS) as usize,
|
||||
max_size: Self::RAM_SIZE
|
||||
};
|
||||
|
||||
Ok(new_self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct SectionInfo {
|
||||
pub name: String,
|
||||
pub start_adr: u64,
|
||||
pub size: usize,
|
||||
pub max_size: usize,
|
||||
}
|
||||
|
||||
impl SectionInfo {
|
||||
fn get_end_adr(&self) -> u64 {
|
||||
self.start_adr + self.size as u64
|
||||
}
|
||||
|
||||
fn get_size_ratio(&self) -> f64 {
|
||||
self.size as f64 / self.max_size as f64
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue