Skip to content

Commit

Permalink
handle different function signature for pre_input_hook on OSX vs linux
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdovzhanyn committed Oct 4, 2024
1 parent 9975bec commit bbf002b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/cli/REPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void REPL::readInput() {
char* input;
string accumulatedInput;

rl_pre_input_hook = prefillIndentation;
rl_pre_input_hook = preInputHook;

while ((input = readline(getPrompt().c_str())) != nullptr) {
accumulatedInput += string(input);
Expand Down Expand Up @@ -77,14 +77,12 @@ void REPL::execute(string source) {
Compiler::getInstance().clearExceptions();
}

int REPL::prefillIndentation(const char *text, int count) {
void REPL::prefillIndentation() {
string indents(delimeterStack.size() * 2, ' ');

rl_insert_text(indents.c_str());
rl_point = rl_end;
rl_redisplay();

return 0;
}

string REPL::getPrompt() {
Expand Down
14 changes: 13 additions & 1 deletion src/cli/REPL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ namespace Theta {

void readInput();

static int prefillIndentation(const char *text, int count);
#ifdef __APPLE__
static int preInputHook(const char *text, int count) {
prefillIndentation();
return 0;
}
#else
static int preInputHook() {
prefillIndentation();
return 0;
}
#endif

static void prefillIndentation();

private:
static stack<char> delimeterStack;
Expand Down

0 comments on commit bbf002b

Please sign in to comment.