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