Skip to content

Commit

Permalink
sim: Use readline library for prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
saursin committed Oct 8, 2023
1 parent dbc7b1a commit 510dab9
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions sim/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
#include <math.h>
#include <map>

#include <readline/readline.h>
#include <readline/history.h>

#define DEBUG_PRINT_T2B
#define DEFAULT_DUMPMEM_PATH "memdump.txt"
#define DEFAULT_TRACEFILE_PATH "trace.vcd"
#define ATOMSIM_PROMPT "atomsim> "


void Atomsim::display_dbg_screen()
{
Expand Down Expand Up @@ -183,9 +188,17 @@ int Atomsim::run_interactive_mode()
while(!backend_.done())
{
// get input
std::string input;
std::cout << ": ";
getline(std::cin, input);
char* raw_input = readline(ATOMSIM_PROMPT);

// Handle Ctrl+D (EOF)
if (!raw_input) {
std::cout << std::endl;
return ATOMSIM_RCODE_EXIT_SIM;
}

// convert to std::string
std::string input(raw_input);
free(raw_input);

// parse input
std::string cmd;
Expand All @@ -204,6 +217,11 @@ int Atomsim::run_interactive_mode()
prev_cmd = cmd;
prev_args = args;

// Add to history
if(input!=""){
add_history(input.c_str());
}

// execute
if (funcs.count(cmd)) // check if command exists
{
Expand Down Expand Up @@ -355,9 +373,6 @@ int Atomsim::cmd_trace(const std::vector<std::string> &args)
else
throw Atomsim_exception("1st arg can be only be \"on\"/\"off\"");
}



return ATOMSIM_RCODE_OK;
}

Expand Down

0 comments on commit 510dab9

Please sign in to comment.