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; }
void Console::registerHint(const std::string& prefix, const std::string& hint) { if (!hasRegisteredHintsCb) { linenoiseSetHintsCallback(hints_cb); hasRegisteredHintsCb = true; } CompletionMap::iterator iter = hintsMap.find(prefix); if (iter == hintsMap.end()) { std::vector<std::string> items; items.push_back(hint); hintsMap[prefix] = items; } else { iter->second[0] = hint; } }
void read_eval_print( stack_frame_t *frame ){ linenoiseSetMultiLine( 1 ); linenoiseSetCompletionCallback( goj_linenoise_complete ); linenoiseSetHintsCallback( goj_linenoise_hints ); really_global_frame = frame; char *buf = ""; unsigned n = 0; token_t *tree; while ( buf ){ buf = linenoise( "> " ); n++; if ( buf ){ tree = parse_scheme_tokens( buf ); if ( tree ){ char varexpr[64]; linenoiseHistoryAdd( buf ); frame->ptr = tree; eval_loop( frame ); snprintf( varexpr, sizeof(varexpr) - 1, "..%u", n ); env_add_var( frame->env, varexpr, frame->end, NO_RECURSE, VAR_IMMUTABLE ); env_add_var( frame->env, "..last", frame->end, NO_RECURSE, VAR_MUTABLE ); printf( "..%u = ", n ); print_token( frame->end, OUTPUT_READABLE ); putchar( '\n' ); } } // Free the statement that was read free( buf ); } }