diff --git a/src/kit/shell/inc/autoTab.h b/src/kit/shell/inc/autoTab.h new file mode 100644 index 0000000000000000000000000000000000000000..7fd35c2059e5785cd379217b3388e5d43062837a --- /dev/null +++ b/src/kit/shell/inc/autoTab.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef __AUTOTAB__ +#define __AUTOTAB__ + +#include "taos.h" +#include "shellCommand.h" + +// main entry +void pressTabKey(TAOS* con, Command* pcmd); + +// show help +void showHelp(); +// auto filling match words with pre +void autoFilling(char* pre, TAOS* conn, Command * pcmd); + +#endif diff --git a/src/kit/shell/inc/shell.h b/src/kit/shell/inc/shell.h index f207a866ddc712165340c06b026aa99081f91c81..d3ae40367ddfaf6701a2942e7be475dc7428f7be 100644 --- a/src/kit/shell/inc/shell.h +++ b/src/kit/shell/inc/shell.h @@ -27,10 +27,13 @@ #define MAX_IP_SIZE 20 #define MAX_HISTORY_SIZE 1000 #define MAX_COMMAND_SIZE 1048586 +#define DOUBLE_COMMAND_SIZE 2*MAX_COMMAND_SIZE #define HISTORY_FILE ".taos_history" #define DEFAULT_RES_SHOW_NUM 100 +#define TAB_KEY 9 + typedef struct SShellHistory { char* hist[MAX_HISTORY_SIZE]; int hstart; diff --git a/src/kit/shell/src/autoTab.c b/src/kit/shell/src/autoTab.c new file mode 100644 index 0000000000000000000000000000000000000000..a5a2838b569cd1366cb76ea0fb2247c869100982 --- /dev/null +++ b/src/kit/shell/src/autoTab.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _BSD_SOURCE +#define _GNU_SOURCE +#define _XOPEN_SOURCE +#define _DEFAULT_SOURCE + +#include "autoTab.h" +#include "os.h" +#include "shellCommand.h" + + +// main entry +void pressTabKey(TAOS* con, Command* pcmd) { + if(pcmd->commandSize == 0) { + // insert help + showHelp(); + showOnScreen(pcmd); + } else { + autoFilling(pcmd->command, con, pcmd); + } + +} + +void autoFilling(char* pre, TAOS* conn, Command * pcmd) { + // first level + + // second level + + + +} + +void showHelp() { + printf("You can run below command: \n"); + printf(" create database \n"); + printf(" create table \n"); + printf(" show databases \n"); + printf(" use databases \n"); + printf(" describe table \n"); +} diff --git a/src/kit/shell/src/shellDarwin.c b/src/kit/shell/src/shellDarwin.c index a1413be1ce4ce6f67516fc09121115f30bbc56f0..a70b5320184d5f30c7de0d0122032d31e0bb7baf 100644 --- a/src/kit/shell/src/shellDarwin.c +++ b/src/kit/shell/src/shellDarwin.c @@ -368,7 +368,7 @@ void *shellLoopQuery(void *arg) { pthread_cleanup_push(cleanup_handler, NULL); - char *command = malloc(MAX_COMMAND_SIZE); + char *command = malloc(DOUBLE_COMMAND_SIZE); if (command == NULL){ tscError("failed to malloc command"); return NULL; @@ -378,7 +378,7 @@ void *shellLoopQuery(void *arg) { do { // Read command from shell. - memset(command, 0, MAX_COMMAND_SIZE); + memset(command, 0, DOUBLE_COMMAND_SIZE); set_terminal_mode(); err = shellReadCommand(con, command); if (err) { diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index 93783b205560604c9d25c9f5dc2e73a239a67b8e..f891766a4f0c305bca3cf6bffee04e03a116586c 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -20,6 +20,7 @@ #include "shellCommand.h" #include "tkey.h" #include "tulog.h" +#include "autoTab.h" #define OPT_ABORT 1 /* �Cabort */ @@ -239,6 +240,8 @@ int32_t shellReadCommand(TAOS *con, char *command) { if (c == EOF) { return c; + } else if (c == TAB_KEY) { + pressTabKey(con, &cmd); } if (c < 0) { // For UTF-8 @@ -393,7 +396,7 @@ void *shellLoopQuery(void *arg) { pthread_cleanup_push(cleanup_handler, NULL); - char *command = malloc(MAX_COMMAND_SIZE); + char *command = malloc(DOUBLE_COMMAND_SIZE); if (command == NULL){ uError("failed to malloc command"); return NULL; @@ -403,7 +406,7 @@ void *shellLoopQuery(void *arg) { do { // Read command from shell. - memset(command, 0, MAX_COMMAND_SIZE); + memset(command, 0, DOUBLE_COMMAND_SIZE); set_terminal_mode(); err = shellReadCommand(con, command); if (err) { diff --git a/src/kit/shell/src/shellMain.c b/src/kit/shell/src/shellMain.c index 5c9dc0995dacecebd10b7f2b77e216ca97157db0..5acff196521fad930783e592c7ca04a263e6f3c1 100644 --- a/src/kit/shell/src/shellMain.c +++ b/src/kit/shell/src/shellMain.c @@ -95,6 +95,7 @@ SShellArguments args = { */ int main(int argc, char* argv[]) { /*setlocale(LC_ALL, "en_US.UTF-8"); */ + printf("hello wolrd shellmain.\n"); if (!checkVersion()) { exit(EXIT_FAILURE); diff --git a/src/kit/shell/src/shellWindows.c b/src/kit/shell/src/shellWindows.c index cb707d9331d3f1f87227e5096b6d7f047d350ebf..b7bda30f89004f6dbe391e11e801dea2854f61e3 100644 --- a/src/kit/shell/src/shellWindows.c +++ b/src/kit/shell/src/shellWindows.c @@ -301,13 +301,13 @@ int32_t shellReadCommand(TAOS *con, char command[]) { void *shellLoopQuery(void *arg) { TAOS *con = (TAOS *)arg; - char *command = malloc(MAX_COMMAND_SIZE); + char *command = malloc(DOUBLE_COMMAND_SIZE); if (command == NULL) return NULL; int32_t err = 0; do { - memset(command, 0, MAX_COMMAND_SIZE); + memset(command, 0, DOUBLE_COMMAND_SIZE); shellPrintPrompt(); // Read command from shell.