Skip to main content
...and one more getkey() <-> getch() mistake I missed.
Source Link
ssokolow
  • 15.5k
  • 7
  • 57
  • 61

According to your clarifying comment, backspace in your terminal is neither curses.KEY_BACKSPACE (int(263)'KEY_BACKSPACE' on mine, but it works) nor \b'\b' (\x08'\x08').

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

getkey() == 'KEY_BACKSPACE' or getch() == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print(os.environ['TERM'])

As a quick hack, you can check all the values it's been observed to take.

if key in ('KEY_BACKSPACE', '\b', '\x7f'):

According to your clarifying comment, backspace in your terminal is neither curses.KEY_BACKSPACE (int(263) on mine, but it works) nor \b (\x08).

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

getkey() == 'KEY_BACKSPACE' or getch() == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print(os.environ['TERM'])

As a quick hack, you can check all the values it's been observed to take.

if key in ('KEY_BACKSPACE', '\b', '\x7f'):

According to your clarifying comment, backspace in your terminal is neither 'KEY_BACKSPACE' nor '\b' ('\x08').

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

getkey() == 'KEY_BACKSPACE' or getch() == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print(os.environ['TERM'])

As a quick hack, you can check all the values it's been observed to take.

if key in ('KEY_BACKSPACE', '\b', '\x7f'):
One overlooked correction for the getch() <-> getkey() confusion
Source Link
ssokolow
  • 15.5k
  • 7
  • 57
  • 61

According to your clarifying comment, backspace in your terminal is neither curses.KEY_BACKSPACE (\x107int(263) on mine, but it works) nor \b (\x08).

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

keygetkey() == 'KEY_BACKSPACE' or getch() == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print(os.environ['TERM'])

As a quick hack, this should get your code working:you can check all the values it's been observed to take.

if key in (curses.KEY_BACKSPACE'KEY_BACKSPACE', '\b', '\x7f'):

According to your clarifying comment, backspace in your terminal is neither curses.KEY_BACKSPACE (\x107 on mine) nor \b (\x08).

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

key == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print(os.environ['TERM'])

As a quick hack, this should get your code working:

if key in (curses.KEY_BACKSPACE, '\b', '\x7f'):

According to your clarifying comment, backspace in your terminal is neither curses.KEY_BACKSPACE (int(263) on mine, but it works) nor \b (\x08).

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

getkey() == 'KEY_BACKSPACE' or getch() == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print(os.environ['TERM'])

As a quick hack, you can check all the values it's been observed to take.

if key in ('KEY_BACKSPACE', '\b', '\x7f'):
Remove spurious backspace in code snip and make it Python 3.x compatible
Source Link
ssokolow
  • 15.5k
  • 7
  • 57
  • 61

According to your clarifying comment, backspace in your terminal is neither curses.KEY_BACKSPACE (\x107 on mine) nor \b (\x08).

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

key == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print (os.environ['TERM']`environ['TERM'])

As a quick hack, this should get your code working:

if key in (curses.KEY_BACKSPACE, '\b', '\x7f'):

According to your clarifying comment, backspace in your terminal is neither curses.KEY_BACKSPACE (\x107 on mine) nor \b (\x08).

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

key == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print os.environ['TERM']`

As a quick hack, this should get your code working:

if key in (curses.KEY_BACKSPACE, '\b', '\x7f'):

According to your clarifying comment, backspace in your terminal is neither curses.KEY_BACKSPACE (\x107 on mine) nor \b (\x08).

Since you're using curses.wrapper(), which calls curses.initscr(), this suggests that something is wrong with either your terminfo database (unlikely) or your terminal configuration (more likely).

key == curses.KEY_BACKSPACE is supposed to work on any properly-configured system, so you're likely to have problems in other applications too.

The TERM environment variable is how the terminal type is communicated to tools which need the functionality beyond basic teletype, so, to fix that, start by checking what the TERM environment variable contains in the environment where you're running Python.

print(os.environ['TERM'])

As a quick hack, this should get your code working:

if key in (curses.KEY_BACKSPACE, '\b', '\x7f'):
Source Link
ssokolow
  • 15.5k
  • 7
  • 57
  • 61
Loading