Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

works on windows #410

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

matthewdeanmartin
Copy link

os.sep + path + skipping readline for windows.

Why I suggest skipping readline:

Me & Chat GPT (back when it thought its name was Assistant) made a pacman game in the terminal that ran on windows. It took win32 API calls. Textual does it better: https://github.com/Textualize/textual/blob/main/src/textual/drivers/win32.py

Also I just wasn't sure what the motivation was. When I run llm in the input field I can use the arrows just fine. The regular input() function allows for left/right arrows. Prefilling an input and up/down arrows would make sense.

Addresses issue : #409

@simonw
Copy link
Owner

simonw commented Jan 27, 2024

Would pyreadline3 work on Windows here though?

llm/setup.py

Line 50 in 8021e12

"pyreadline3; sys_platform == 'win32'",

@simonw
Copy link
Owner

simonw commented Jan 27, 2024

Pushed a tiny fix for this failing test:

        if os.name != "nt":
            # Should be chmod 600
>           assert oct(keys_path.stat().st_mode)[-3:] == "600"

tests/test_keys.py:36: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <_pytest._py.path.Stat object at 0x7f598d774490>, name = 'st_mode'

    def __getattr__(self, name: str) -> Any:
>       return getattr(self._osstatresult, "st_" + name)
E       AttributeError: 'os.stat_result' object has no attribute 'st_st_mode'

@matthewdeanmartin
Copy link
Author

Oh that bot! It changed mode to st_mode and I didn't see it fail.

pyreadline3 no longer throws on import, but doesn't handle that key. I get the impression that it has only reimplemented some of what readline can do.

File "E:\github\llm\llm\cli.py", line 347, in chat
    readline.parse_and_bind("\\e[D: backward-char")
  File "E:\.virtualenv\llm-Ou002Y_x\Lib\site-packages\pyreadline3\rlmain.py", line 112, in parse_and_bind
    self.mode._bind_key(key, func)
  File "E:\.virtualenv\llm-Ou002Y_x\Lib\site-packages\pyreadline3\modes\basemode.py", line 181, in _bind_key
    keyinfo = make_KeyPress_from_keydescr(key.lower()).tuple()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\.virtualenv\llm-Ou002Y_x\Lib\site-packages\pyreadline3\keysyms\common.py", line 138, in make_KeyPress_from_keydescr
    raise IndexError("Not a valid key: '%s'" % keydescr)
IndexError: Not a valid key: '\e[d'

I still don't know where the left/right arrows are failing to work so I'm not sure about how to go about implementing it for windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants