Skip to content

Commit

Permalink
add step over and step back buttons (#54)
Browse files Browse the repository at this point in the history
Added step over and step back buttons to jump to the next time a scope
with the current level comes up. This is useful for stepping over inner
functions and focusing solely on your current scope level.
  • Loading branch information
Vandesm14 authored Jun 24, 2024
1 parent c1a0c6c commit e6635a7
Showing 1 changed file with 90 additions and 19 deletions.
109 changes: 90 additions & 19 deletions stack-debugger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,65 @@ impl DebuggerApp {
fn stack_ops_len(&self) -> usize {
self.context.journal().as_ref().unwrap().entries().len()
}

fn step_over(&mut self) {
let index = self.index;
if let Some(entry) = self
.context
.journal()
.as_ref()
.unwrap()
.entries()
.get(index)
{
let scope_level = entry.scope_level;
let next_index = self
.context
.journal()
.as_ref()
.unwrap()
.entries()
.iter()
.enumerate()
.skip(index + 1)
.find(|(i, entry)| entry.scope_level == scope_level)
.map(|(i, _)| i);

if let Some(next_index) = next_index {
self.index = next_index;
}
}
}

fn step_over_rev(&mut self) {
let index = self.index;
if let Some(entry) = self
.context
.journal()
.as_ref()
.unwrap()
.entries()
.get(index)
{
let scope_level = entry.scope_level;
let next_index = self
.context
.journal()
.as_ref()
.unwrap()
.entries()
.iter()
.enumerate()
.rev()
.skip(self.stack_ops_len() - index)
.find(|(_, entry)| entry.scope_level == scope_level)
.map(|(i, _)| i);

if let Some(next_index) = next_index {
self.index = next_index;
}
}
}
}

impl eframe::App for DebuggerApp {
Expand Down Expand Up @@ -289,27 +348,39 @@ impl eframe::App for DebuggerApp {
ui.label(format!("Error: {err}"));
}

ui.horizontal(|ui| {
if ui.button("Reload").clicked() {
self.reload();
}
ui.vertical(|ui| {
ui.horizontal(|ui| {
if ui.button("Reload").clicked() {
self.reload();
}

if ui.button("<|").clicked() {
self.index = 0;
}
if ui.button("<").clicked() {
self.index = self.index.saturating_sub(1);
}
if ui.button("<|").clicked() {
self.index = 0;
}
if ui.button("<").clicked() {
self.index = self.index.saturating_sub(1);
}

if ui.button(">").clicked() {
self.index = self
.index
.add(1)
.min(self.stack_ops_len().saturating_sub(1));
}
if ui.button("|>").clicked() {
self.index = self.stack_ops_len().saturating_sub(1);
}
if ui.button(">").clicked() {
self.index = self
.index
.add(1)
.min(self.stack_ops_len().saturating_sub(1));
}
if ui.button("|>").clicked() {
self.index = self.stack_ops_len().saturating_sub(1);
}
});

ui.horizontal(|ui| {
if ui.button("step back").clicked() {
self.step_over_rev();
}

if ui.button("step over").clicked() {
self.step_over();
}
})
});

let max = self.stack_ops_len().saturating_sub(1);
Expand Down

0 comments on commit e6635a7

Please sign in to comment.