Use GNU readline for input.
This commit is contained in:
parent
5f681a5971
commit
ecfbd8deae
|
@ -7,6 +7,6 @@ set(CMAKE_CXX_STANDARD 11)
|
|||
|
||||
add_subdirectory(external/libabacus)
|
||||
add_executable(cmdAbacus src/main.cpp)
|
||||
target_link_libraries(cmdAbacus abacus ${MPFR_LIBRARIES})
|
||||
target_link_libraries(cmdAbacus abacus ${MPFR_LIBRARIES} readline)
|
||||
target_include_directories(cmdAbacus PUBLIC include ${MPFR_INCLUDE_DIRS})
|
||||
target_compile_options(cmdAbacus PUBLIC ${MPFR_CFLAGS_OTHER})
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -1,6 +1,8 @@
|
|||
#include <iostream>
|
||||
#include <map>
|
||||
#include <mpfr.h>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
extern "C" {
|
||||
#include "libabacus.h"
|
||||
#include "value.h"
|
||||
|
@ -299,7 +301,7 @@ abacus::~abacus() {
|
|||
}
|
||||
int main() {
|
||||
abacus ab;
|
||||
std::string buffer;
|
||||
rl_bind_key('\t', rl_insert);
|
||||
|
||||
ab.add_function("quit", function_quit, "()->unit");
|
||||
ab.add_function("request_precision", function_request_precision, "(num)->unit");
|
||||
|
@ -322,8 +324,11 @@ int main() {
|
|||
ab.add_operator_prefix("-", "negate");
|
||||
|
||||
while(!close_requested) {
|
||||
std::cout << "> ";
|
||||
std::getline(std::cin, buffer);
|
||||
char* data = readline(" > ");
|
||||
std::string buffer(data);
|
||||
add_history(data);
|
||||
free(data);
|
||||
|
||||
abacus_ref value = ab.run(buffer);
|
||||
if(value == nullptr) {
|
||||
std::cout << "Invalid expression." << std::endl;
|
||||
|
|
Loading…
Reference in New Issue
Block a user