Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thomasballinger/simplerepl
https://github.com/thomasballinger/simplerepl
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/thomasballinger/simplerepl
- Owner: thomasballinger
- Created: 2015-12-21T20:09:15.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-01T18:41:30.000Z (about 9 years ago)
- Last Synced: 2024-12-16T13:43:31.062Z (about 1 month ago)
- Language: Python
- Size: 4.88 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Want to make a simple interactive REPL in Python?
The first step might be:
while True:
i = raw_input('enter a command: ')
print(i.upper())But if you want to create a richer experience, one that might update the
screen after each keystroke the user types, then you might need to go deeper.Get started by installing blessed
pip install blessed
Now let's update the screen after each keystroke:
```
import sys
import blessedterm = blessed.Terminal()
line = ''with term.cbreak():
while True:
inp = term.inkey()
if inp == '\n':
print('')
print("you hit enter!")
print(line.upper())
line = ''
else:
line += inp
sys.stdout.write('\r')
sys.stdout.write(line)
sys.stdout.flush()
```what do you want to do next?
* [ask the user for a limited number of characters](presseight.py)
* [update the screen with more information](step2.py)
* [update on keystroke whether the current line is valid](step3.py)
(see step2.py and step3.py for this)