cookiecutter icon indicating copy to clipboard operation
cookiecutter copied to clipboard

`import readline` to allow backspace in CLI.

Open aryamccarthy opened this issue 9 years ago • 10 comments

  • Cookiecutter version: '1.4.0'
  • Template project url: https://github.com/drivendata/cookiecutter-data-science
  • Python version: 3.5.2
  • Operating System: macOS 10.12.3

Description:

Importing the readline package would allow users to backspace in the prompts without it rendering as ^H. No other change would be needed.

aryamccarthy avatar Dec 24 '16 22:12 aryamccarthy

Hi @aryamccarthy! 👋

Thank you for opening an issue. I'm afraid I don't quite understand.

Are you referring to the built-in readlin package?

hackebrot avatar Dec 30 '16 17:12 hackebrot

Hi, @hackebrot! Thanks for writing.

Yes, that's the one I'm referring to. This StackOverflow discussion explains that simply importing the readline package alters how input() works.

I have sloppy fingers, and I make mistakes when trying to set up my cookiecutter templates. Backspace and arrow keys working as expected would let me fix those instead of quitting the program and starting all over.

aryamccarthy avatar Dec 30 '16 21:12 aryamccarthy

Cookiecutter uses click for prompting. We never call input() directly.

hackebrot avatar Dec 30 '16 21:12 hackebrot

Hmm. Is there a click-compatible way to improve this functionality?

aryamccarthy avatar Jan 01 '17 19:01 aryamccarthy

Hey @hackebrot, any updates on that topic?

I seem to run into the same problem of @aryamccarthy. During the cookiecutter CLI "question" process I occasionaly have to hit the backspace - which messes up the variables.

For every backspace I get an ? into the variable name. Assuming that my repo is named my_repo but I first wrote my_repu and hit backspace one to change it to my_repo, cookiecutter will give me my_repo?u instead of my_repo.

I hope this makes the issue a bit clearer.

Cheers Joshua

jgoerner avatar Sep 06 '17 08:09 jgoerner

@hackebrot , +1 for jgoerner's comment above.

robinovitch61 avatar Sep 22 '17 18:09 robinovitch61

+1 I just encountered the same problem. Backspace in the prompt window renders as ^H on MacOSX.

jbusecke avatar Feb 07 '19 17:02 jbusecke

Also encountering the same problem, anyone trying to fix this?

ShayNehmad-RecoLabs avatar Dec 09 '21 09:12 ShayNehmad-RecoLabs

Same problem on Ubuntu (WSL2)

shadycuz avatar May 14 '23 13:05 shadycuz

Adding a local extension with import readline works as a workaround for me.

cookiecutter.json

{
    ...
    "_extensions": ["local_extensions.fix_readline"]
  }

local_extensions.py

import readline
from cookiecutter.utils import simple_filter


@simple_filter
def fix_readline():
    pass

rquintas avatar Nov 08 '23 17:11 rquintas