mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 11:57:43 +08:00
master_ctl: support using readline optional.
This commit is contained in:
parent
056cb8d060
commit
e7800ce7c9
@ -9,7 +9,7 @@ CFLAGS = -c -g -W -Wall -Wcast-qual -Wcast-align \
|
||||
###########################################################
|
||||
#Check system:
|
||||
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
|
||||
SYSLIB = -lreadline -lcurses -lpthread -lz
|
||||
SYSLIB = -lpthread -lz
|
||||
CHECKSYSRES = @echo "Unknow system type!";exit 1
|
||||
OSNAME = $(shell uname -s)
|
||||
OSTYPE = $(shell uname -m)
|
||||
@ -20,20 +20,28 @@ endif
|
||||
|
||||
ifeq ($(findstring on, $(HAS_READLINE)), on)
|
||||
CFLAGS += -DHAS_READLINE
|
||||
SYSLIB += -lreadline -lcurses
|
||||
else ifeq ($(findstring ON, $(HAS_READLINE)), ON)
|
||||
CFLAGS += -DHAS_READLINE
|
||||
SYSLIB += -lreadline -lcurses
|
||||
else ifeq ($(findstring yes, $(HAS_READLINE)), yes)
|
||||
CFLAGS += -DHAS_READLINE
|
||||
SYSLIB += -lreadline -lcurses
|
||||
else ifeq ($(findstring YES, $(HAS_READLINE)), YES)
|
||||
CFLAGS += -DHAS_READLINE
|
||||
SYSLIB += -lreadline -lcurses
|
||||
else ifeq ($(findstring on, $(has_readline)), on)
|
||||
CFLAGS += -DHAS_READLINE
|
||||
SYSLIB += -lreadline -lcurses
|
||||
else ifeq ($(findstring ON, $(has_readline)), ON)
|
||||
CFLAGS += -DHAS_READLINE
|
||||
SYSLIB += -lreadline -lcurses
|
||||
else ifeq ($(findstring yes, $(has_readline)), yes)
|
||||
CFLAGS += -DHAS_READLINE
|
||||
SYSLIB += -lreadline -lcurses
|
||||
else ifeq ($(findstring YES, $(has_readline)), YES)
|
||||
CFLAGS += -DHAS_READLINE
|
||||
SYSLIB += -lreadline -lcurses
|
||||
endif
|
||||
|
||||
# For FreeBSD
|
||||
@ -148,7 +156,7 @@ all: RM $(OBJ)
|
||||
@echo ""
|
||||
RM:
|
||||
rm -f $(PROG)
|
||||
clean:
|
||||
clean cl:
|
||||
rm -f $(PROG)
|
||||
rm -f $(OBJ)
|
||||
rebuild rb: clean all
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef HAS_READLINE
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#endif
|
||||
|
||||
#include "http_request.h"
|
||||
|
||||
static bool __verbose = false;
|
||||
@ -508,7 +512,9 @@ static bool do_quit(const std::vector<acl::string>&, const char*, const char*)
|
||||
static bool do_clear(const std::vector<acl::string>&, const char*, const char*)
|
||||
{
|
||||
#if !defined(__APPLE__)
|
||||
#ifdef HAS_READLINE
|
||||
rl_clear_screen(0, 0);
|
||||
#endif
|
||||
#endif
|
||||
printf("\r\n");
|
||||
return true;
|
||||
@ -516,17 +522,27 @@ static bool do_clear(const std::vector<acl::string>&, const char*, const char*)
|
||||
|
||||
static void getline(acl::string& out)
|
||||
{
|
||||
#ifdef HAS_READLINE
|
||||
const char* prompt = "\033[1;34;40mmaster_ctl>\033[0m ";
|
||||
char* ptr = readline(prompt);
|
||||
if (ptr == NULL)
|
||||
#else
|
||||
printf("master_ctl> ");
|
||||
fflush(stdout);
|
||||
char buf[1024];
|
||||
char* ptr = fgets(buf, (int) sizeof(buf), stdin);
|
||||
#endif
|
||||
if (ptr == NULL || *ptr == 0)
|
||||
{
|
||||
printf("Bye!\r\n");
|
||||
exit(0);
|
||||
}
|
||||
out = ptr;
|
||||
out.trim_right_line();
|
||||
|
||||
#ifdef HAS_READLINE
|
||||
if (!out.empty() && !out.equal("y", false) && !out.equal("n", false))
|
||||
add_history(out.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct {
|
||||
|
Loading…
Reference in New Issue
Block a user