Skip to content

Commit

Permalink
Virtual key listener CTRL+C to halt current running program.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Apr 15, 2024
1 parent ed9403f commit bb6be4d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/shell_example/shell_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ void setup() {
vm = new RishkaVM();
vm->initialize(&Terminal);

// Virtual key listener to halt program
Terminal.onVirtualKeyItem = [&](VirtualKeyItem * vkItem) {
if(vkItem->CTRL && vkItem->vk == VirtualKey::VK_c && vm->isRunning()) {
// Stop the VM if CTRL+C was pressed
vm->stopVM();
vm->reset();

Terminal.println("^C");
}
};

// Print prompt
Terminal.print("\e[32m[\e[97m" + vm->getWorkingDirectory() + "\e[97m\e[32m]~\e[97m ");
}
Expand Down

0 comments on commit bb6be4d

Please sign in to comment.