Ejemplo n.º 1
0
int run_repl(JSContextRef ctx) {
	global_ctx = ctx;

	current_ns = strdup("cljs.user");
	current_prompt = form_prompt(current_ns, false);

	// Per-type initialization

	if (!config.dumb_terminal) {
		char *home = getenv("HOME");
		if (home != NULL) {
			char history_name[] = ".planck_history";
			int len = strlen(home) + strlen(history_name) + 2;
			history_path = malloc(len * sizeof(char));
			snprintf(history_path, len, "%s/%s", home, history_name);

			linenoiseHistoryLoad(history_path);

			// TODO: load keymap
		}

		linenoiseSetMultiLine(1);
		linenoiseSetCompletionCallback(completion);
		linenoiseSetHighlightCallback(highlight);
		linenoiseSetHighlightCancelCallback(highlight_cancel);
	}

	run_cmdline_loop(ctx);

	return exit_value;
}
Ejemplo n.º 2
0
void lineedit_initialize()
{
    memset(&l, 0, sizeof(l));
    linenoiseSetMultiLine(1);
    /* Set the completion callback. This will be called every time the
     * user uses the <tab> key. */
    // linenoiseSetCompletionCallback(completion);

    /* Load history from file. The history file is just a plain text file
     * where entries are separated by newlines. */
    linenoiseHistoryLoad("history.txt");
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
Archivo: repl.c Proyecto: mfikes/planck
int run_repl() {
    repl_t *repl = make_repl();
    s_repl = repl;

    repl->current_ns = strdup("cljs.user");
    repl->current_prompt = form_prompt(repl->current_ns, false);

    // Per-type initialization

    if (!config.dumb_terminal) {
        char *home = getenv("HOME");
        if (home != NULL) {
            char history_name[] = ".planck_history";
            size_t len = strlen(home) + strlen(history_name) + 2;
            repl->history_path = malloc(len * sizeof(char));
            snprintf(repl->history_path, len, "%s/%s", home, history_name);

            linenoiseHistoryLoad(repl->history_path);

            exit_value = load_keymap(home);
            if (exit_value != EXIT_SUCCESS) {
                return exit_value;
            }
        }

        linenoiseSetMultiLine(1);
        linenoiseSetCompletionCallback(completion);
        linenoiseSetHighlightCallback(highlight);
        linenoiseSetHighlightCancelCallback(highlight_cancel);
    }

    if (!config.dumb_terminal) {
        cljs_set_print_sender(&linenoisePrintNow);
    }

    if (config.socket_repl_port) {
        pthread_t thread;
        pthread_create(&thread, NULL, accept_connections, NULL);
    }

    run_cmdline_loop(repl);

    return exit_value;
}
Ejemplo n.º 6
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);
    }
Ejemplo n.º 7
0
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 );
	}
}
Ejemplo n.º 8
0
SEXP R_readline_read_line(SEXP prompt, SEXP multiline, SEXP history,
			  SEXP completions) {
  char *line;
  SEXP result;

  linenoiseSetEncodingFunctions(
    linenoiseUtf8PrevCharLen,
    linenoiseUtf8NextCharLen,
    linenoiseUtf8ReadCode);

  if (!isNull(history)) linenoiseHistoryLoad(CHAR(STRING_ELT(history, 0)));
  if (!isNull(completions)) {
    R_readline_completions = completions;
    linenoiseSetCompletionCallback(R_readline_completion);
  }

  linenoiseSetMultiLine(LOGICAL(multiline)[0]);
  line = linenoise(CHAR(STRING_ELT(prompt, 0)));

  result = ScalarString(mkCharCE(line, CE_UTF8));
  free(line);

  return result;
}
Ejemplo n.º 9
0
void Console::setMultiLine(bool multiLine)
{
  linenoiseSetMultiLine(multiLine);
}