xonsh / xonsh

:shell: Python-powered shell. Full-featured and cross-platform.
http://xon.sh
Other
8.16k stars 633 forks source link

Windows: paste performance #5292

Open brokedarius opened 4 months ago

brokedarius commented 4 months ago

xonfig

```xsh import datetime from prompt_toolkit import prompt from prompt_toolkit.history import InMemoryHistory from prompt_toolkit.key_binding import KeyBindings from prompt_toolkit.keys import Keys bindings = KeyBindings() @bindings.add(Keys.Up) def history_search_backward(event): event.current_buffer.history_backward() @bindings.add(Keys.Down) def history_search_forward(event): event.current_buffer.history_forward() $PROMPT = '{INTENSE_GREEN}[{YELLOW}{user}{RESET}@{BLUE}{hostname}{RESET}:{cwd}─{INTENSE_YELLOW}[' + str(datetime.date.today()) + ']─{INTENSE_GREEN}[{localtime}]{INTENSE_RED}──>{RESET} ' $XONSH_HISTORY_BACKEND = 'sqlite' $FORCE_POSIX_PATHS = True $XONSH_SHOW_TRACEBACK = True $INTENSIFY_COLORS_ON_WIN ```

Expected Behavior

When pasting text, it should take into account tab indents as well as spaces not only that but it should also do it much faster.

Current Behavior

When I paste functions and such, I have to wait several seconds/minutes for it to paste and only for it most of the time to not have it's tab indents/spaces taken into accounts. Kind of ironic for a python shell.

Steps to Reproduce

Copy pasting functions with tab indents or spaces as indents (spaces seem to have a bit less issues?)

anki-code commented 4 months ago

I can't reproduce this. Please provide your xonfig as well as example.

brokedarius commented 4 months ago

I can't reproduce this. Please provide your xonfig as well as example.

Seems to be only affecting functions with tab indents not spaces after further testing so apologies for lumping them in.

For instance can you please try pasting this small example function in a xonsh shell if you don't mind?:

def save_toml(toml_dict: dict[str, str], toml_path: str) -> None:

    with open(toml_path, 'w') as c:
        c.write(tomlkit.dumps(asdict(toml_dict)))

Also I am on windows, tried it on both tabby and windows terminal where its very slow to finish pasting, sometimes it does not when the function is a bit bigger. On conhost it pastes rather fast but the tab indents are not respected either.

gforsyth commented 3 months ago

Can you confirm that pasting works as you expect when xonsh isn't in the mix?

brokedarius commented 3 months ago

yes works fine from regular python console sorry I was away for a little while

brokedarius commented 1 day ago

I noticed something:

I opened the project in VSCode and realized that in ptk_shell/key_bindings.py if you change this function from this:

@Condition
def tab_insert_indent():
    """Check if <Tab> should insert indent instead of starting autocompletion.
    Checks if there are only whitespaces before the cursor - if so indent
    should be inserted, otherwise autocompletion.

    """
    before_cursor = get_app().current_buffer.document.current_line_before_cursor

    return bool(before_cursor.isspace())

to this:

@Condition
def tab_insert_indent():
    """Check if <Tab> should insert indent instead of starting autocompletion.
    Checks if there are only whitespaces before the cursor - if so indent
    should be inserted, otherwise autocompletion.

    """
    before_cursor = get_app().current_buffer.document.current_line_before_cursor

    return True

It somehow applies a 'wall patch' to my issue but obviously I lose the ability to tab complete which I don't care for personally but now at least we know that in this function the boolean is most likely always evaluating to False when pasting text because of this expression? get_app().current_buffer.document.current_line_before_cursor.isspace().

Either that or some interference due to the fact that the TAB key is reserved for other operations? Let me know.

(Only tested on Windows 10)