Skip to content

Commit

Permalink
fix: backspace key for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
numbertheory committed May 11, 2024
1 parent b1bd652 commit cd11fa7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags')
uses: actions/setup-python@v1
with:
python-version: 3.10.5
python-version: 3.10.14
- name: Install pypa/build
if: startsWith(github.ref, 'refs/tags')
run: >-
Expand Down
9 changes: 8 additions & 1 deletion dashport/prompt.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#! /usr/bin/env python3
from curses.textpad import Textbox
import curses
import platform


def user_prompt(app, **kwargs):
command_line_entered = []
cursor_x = kwargs.get("x", 0)
cursor_y = kwargs.get("y", 0)

def backspace_key():
if platform.system().lower() == "linux":
return 263
else:
return 127

def validate_text(x):
invalid_chars = [127, 260, 261, 10]
if x == 260 and app.user_prompt_position != 0:
Expand All @@ -17,7 +24,7 @@ def validate_text(x):
if x not in invalid_chars and curses.ascii.isprint(x):
command_line_entered.insert(app.user_prompt_position, chr(x))
app.user_prompt_position += 1
if x == 127 and len(command_line_entered) > 0:
if x == backspace_key() and len(command_line_entered) > 0:
try:
command_line_entered.pop(app.user_prompt_position - 1)
except IndexError:
Expand Down

0 comments on commit cd11fa7

Please sign in to comment.