Пример #1
0
//------------------------------------------------------------------------------
static int startup_hook()
{
    static int initialised = 0;
    if (!initialised)
    {
        // This is a bit of a hack. Ideally we should take care of this in
        // the termcap functions.
        _rl_term_forward_char = "\013";
        _rl_term_clreol = "\001";

        rl_redisplay_function = display;
        rl_getc_function = getc_impl;

        rl_completer_quote_characters = "\"";
        rl_ignore_some_completions_function = postprocess_matches;
        rl_basic_word_break_characters = " <>|";
        rl_completer_word_break_characters = " <>|";
        rl_completion_display_matches_hook = display_matches;
        rl_attempted_completion_function = alternative_matches;

        rl_add_funmap_entry("clink-completion-shim", completion_shim);
        rl_add_funmap_entry("clear-line", clear_line);
        rl_add_funmap_entry("paste-from-clipboard", paste_from_clipboard);

        initialise_lua();
        load_history();
        rl_re_read_init_file(0, 0);
        rl_visible_stats = 0;               // serves no purpose under win32.

        initialised = 1;
    }
    
    return 0;
}
Пример #2
0
Файл: lua.c Проект: genba/clink
//------------------------------------------------------------------------------
static int reload_lua_state(int count, int invoking_key)
{
    shutdown_lua();
    initialise_lua();
    return 1;
}
Пример #3
0
//------------------------------------------------------------------------------
static char* call_readline_impl(const char* prompt)
{
    static int initialised = 0;
    int expand_result;
    char* text;
    char* expanded;
    char* prepared_prompt;
    char cwd_cache[MAX_PATH];

    // Initialisation
    if (!initialised)
    {
        initialise_clink_settings();
        initialise_lua();
        load_history();

        rl_catch_signals = 0;
        rl_startup_hook = initialise_hook;
        initialised = 1;
    }

    // If no prompt was provided assume the line is prompted already and
    // extract it. If a prompt was provided filter it through Lua.
    prepared_prompt = NULL;
    if (prompt == NULL)
    {
        prepared_prompt = extract_prompt(1);

        // Even though we're not going to display filtered result the extracted
        // prompt is run through Lua. This is a little bit of a hack, but helps
        // to keep behaviour consistent.
        if (prepared_prompt != NULL)
        {
            char buffer[1024];

            str_cpy(buffer, prepared_prompt, sizeof(buffer));
            lua_filter_prompt(buffer, sizeof_array(buffer));
        }
    }
    else
    {
        prepared_prompt = filter_prompt(prompt);
    }

    GetCurrentDirectory(sizeof_array(cwd_cache), cwd_cache);

    // Call readline
    do
    {
        rl_already_prompted = (prompt == NULL);
        text = readline(prepared_prompt ? prepared_prompt : "");
        if (!text)
        {
            goto call_readline_epilogue;
        }

        // Expand history designators in returned buffer.
        expanded = NULL;
        expand_result = history_expand(text, &expanded);
        if (expand_result < 0)
        {
            free(expanded);
        }
        else
        {
            free(text);
            text = expanded;

            // If there was some expansion then display the expanded result.
            if (expand_result > 0)
            {
                hooked_fprintf(NULL, "History expansion: %s\n", text);
            }
        }

        add_to_history(text);
    }
    while (!text || expand_result == 2);

call_readline_epilogue:
    free_prompt(prepared_prompt);
    SetCurrentDirectory(cwd_cache);
    return text;
}
Пример #4
0
Файл: rl.c Проект: Tafhim/clink
//------------------------------------------------------------------------------
static char* call_readline_impl(const char* prompt)
{
    static int initialised = 0;
    int expand_result;
    char* text;
    char* expanded;
    char* prepared_prompt;
    char cwd_cache[MAX_PATH];

    // Turn off EOL wrapping as Readline will take care of it.
    {
        HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleMode(handle_stdout, ENABLE_PROCESSED_OUTPUT);
    }

    // Initialisation
    if (!initialised)
    {
        initialise_clink_settings();
        initialise_lua();
        initialise_fwrite();

        load_history();
        history_inhibit_expansion_function = history_expand_control;

        rl_catch_signals = 0;
        rl_startup_hook = initialise_hook;
        initialised = 1;
    }

    // If no prompt was provided assume the line is prompted already and
    // extract it. If a prompt was provided filter it through Lua.
    prepared_prompt = NULL;
    if (prompt == NULL)
    {
        prepared_prompt = extract_prompt(1);

        // Even though we're not going to display filtered result the extracted
        // prompt is run through Lua. This is a little bit of a hack, but helps
        // to keep behaviour consistent.
        if (prepared_prompt != NULL)
        {
            char buffer[1024];

            str_cpy(buffer, prepared_prompt, sizeof(buffer));
            lua_filter_prompt(buffer, sizeof_array(buffer));
        }
    }
    else
    {
        prepared_prompt = filter_prompt(prompt);
    }

    GetCurrentDirectory(sizeof_array(cwd_cache), cwd_cache);

    do
    {
        // Call readline
        rl_already_prompted = (prompt == NULL);
        text = readline(prepared_prompt ? prepared_prompt : "");
        if (!text)
        {
            goto call_readline_epilogue;
        }

        // Expand history designators in returned buffer.
        expanded = NULL;
        expand_result = expand_from_history(text, &expanded);
        if (expand_result > 0 && expanded != NULL)
        {
            free(text);
            text = expanded;

            // If there was some expansion then display the expanded result.
            if (expand_result > 0)
            {
                hooked_fprintf(NULL, "History expansion: %s\n", text);
            }
        }

        // Should we read the history from disk.
        if (get_clink_setting_int("history_io"))
        {
            load_history();
            add_to_history(text);
            save_history();
        }
        else
            add_to_history(text);
    }
    while (!text || expand_result == 2);

call_readline_epilogue:
    free_prompt(prepared_prompt);
    SetCurrentDirectory(cwd_cache);
    return text;
}