static int l_historysetmaxlen(lua_State *L) { int len = luaL_checkinteger(L, 1); if(! linenoiseHistorySetMaxLen(len)) { return handle_ln_error(L); } return handle_ln_ok(L); }
int main(int argc, char *argv[]) { char *line; #ifdef HAVE_MULTILINE /* Note: multiline support has not yet been integrated */ char *prgname = argv[0]; /* Parse options, with --multiline we enable multi line editing. */ while(argc > 1) { argc--; argv++; if (!strcmp(*argv,"--multiline")) { linenoiseSetMultiLine(1); printf("Multi-line mode enabled.\n"); } else { fprintf(stderr, "Usage: %s [--multiline]\n", prgname); exit(1); } } #endif #ifndef NO_COMPLETION /* Set the completion callback. This will be called every time the * user uses the <tab> key. */ linenoiseSetCompletionCallback(completion); #endif /* Load history from file. The history file is just a plain text file * where entries are separated by newlines. */ linenoiseHistoryLoad("history.txt"); /* Load the history at startup */ /* Now this is the main loop of the typical linenoise-based application. * The call to linenoise() will block as long as the user types something * and presses enter. * * The typed string is returned as a malloc() allocated string by * linenoise, so the user needs to free() it. */ while((line = linenoise("hello> ")) != NULL) { /* Do something with the string. */ if (line[0] != '\0' && line[0] != '/') { printf("echo: '%s'\n", line); linenoiseHistoryAdd(line); /* Add to the history. */ linenoiseHistorySave("history.txt"); /* Save the history on disk. */ } else if (!strncmp(line,"/historylen",11)) { /* The "/historylen" command will change the history len. */ int len = atoi(line+11); linenoiseHistorySetMaxLen(len); } else if (line[0] == '/') { printf("Unreconized command: %s\n", line); } free(line); } return 0; }
int main(int UNUSED(argc), char *argv[]) { // int i; const int num_threads = 2; pthread_t tid[num_threads]; // void *status; struct listen_param lis_para; struct send_param send_para; char *line; //mtrace(); que_msg = CreateQueue(100); sem_init(&sem_msg, 0, 0); memset(&dev_map, 0, sizeof(dev_map)); lis_para.port = SERVER_PORT; lis_para.receive_thread = receive_thread; pthread_create(&tid[0], NULL, listen_thread, &lis_para); send_para.que_msg = que_msg; send_para.mutex_msg = &mutex_msg; send_para.sem_msg = &sem_msg; pthread_create(&tid[1], NULL, send_thread, &send_para); linenoiseHistoryLoad("hist-srv.txt"); /* Load the history at startup */ while((line = linenoise("srv> ")) != NULL) { /* Do something with the string. */ if (line[0] != '\0' && line[0] != '/') { //printf("echo: '%s'\n", line); linenoiseHistoryAdd(line); /* Add to the history. */ linenoiseHistorySave("hist-srv.txt"); /* Save the history on disk. */ cmd_handle(0, line); } else if (!strncmp(line,"/q",2)) { free(line); break; } else if (!strncmp(line,"/historylen",11)) { /* The "/historylen" command will change the history len. */ int len = atoi(line+11); linenoiseHistorySetMaxLen(len); } else if (line[0] == '/') { printf("Unreconized command: %s\n", line); } else { printf("\n"); } free(line); } // for (i = 0; i < num_threads; i++) // pthread_join(tid[i],&status); return 0; }
void initialize_console() { /* Disable buffering on stdin */ setvbuf(stdin, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); /* Configure UART. Note that REF_TICK is used so that the baud rate remains * correct while APB frequency is changing in light sleep mode. */ uart_config_t uart_config; memset(&uart_config, 0, sizeof(uart_config)); uart_config.baud_rate = CONFIG_CONSOLE_UART_BAUDRATE; uart_config.data_bits = UART_DATA_8_BITS; uart_config.parity = UART_PARITY_DISABLE; uart_config.stop_bits = UART_STOP_BITS_1; uart_config.use_ref_tick = true; ESP_ERROR_CHECK(uart_param_config((uart_port_t) CONFIG_CONSOLE_UART_NUM, &uart_config)); /* Install UART driver for interrupt-driven reads and writes */ ESP_ERROR_CHECK(uart_driver_install((uart_port_t) CONFIG_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0)); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); /* Initialize the console */ esp_console_config_t console_config; memset(&console_config, 0, sizeof(console_config)); console_config.max_cmdline_args = 8; console_config.max_cmdline_length = 256; #if CONFIG_LOG_COLORS console_config.hint_color = atoi(LOG_COLOR_CYAN); #endif ESP_ERROR_CHECK(esp_console_init(&console_config)); /* Configure linenoise line completion library */ /* Enable multiline editing. If not set, long commands will scroll within * single line. */ linenoiseSetMultiLine(1); /* Tell linenoise where to get command completions and hints */ linenoiseSetCompletionCallback(&esp_console_get_completion); linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint); /* Set command history size */ linenoiseHistorySetMaxLen(100); }
int main(int argc, char *argv[]) { int err; char *host = "127.0.0.1"; int port = 1276; char *prompt = "lamb"; /* Signal event processing */ lamb_signal_processing(); /* Start main event thread */ int sock; err = lamb_sock_connect(&sock, host, port); if (err) { fprintf(stderr, "Can't connect to %s server\n", host); return -1; } char *line; char *prgname = argv[0]; linenoiseSetCompletionCallback(completion); linenoiseSetHintsCallback(hints); linenoiseHistoryLoad(".lamb_history"); linenoiseHistorySetMaxLen(1000); while((line = linenoise("lamb> ")) != NULL) { /* Do something with the string. */ if (line[0] != '\0') { printf("echo: %s\n", line); linenoiseHistoryAdd(line); linenoiseHistorySave(".lamb_history"); } else if (line[0] != '\0' && !strncmp(line, "show client", 11)) { int id = atoi(line + 11); lamb_show_client(sock, id); linenoiseHistoryAdd(line); linenoiseHistorySave(".lamb_history"); } else if (line[0] != '\0') { printf("Unknown Command: '%s'\n", line); } free(line); } return 0; }
static void interactiveLoop() { setjmp(recovery); linenoiseSetMultiLine(1); linenoiseHistorySetMaxLen(100); char *buf; while ((buf = linenoise("clay> ")) != NULL) { linenoiseHistoryAdd(buf); string line = stripSpaces(buf); if (line[0] == ':') { replCommand(line.substr(1, line.size() - 1)); } else { eval(line); } free(buf); } engine->runStaticConstructorsDestructors(true); }
void stifle_history(int max) { linenoiseHistorySetMaxLen(max); }
void Console::setHistoryMaxLen(int maxLen) { linenoiseHistorySetMaxLen(maxLen); }