0

I have been looking everywhere to figure out how to delete the last character on my curses prompt with my backspace.

My backspace is returning ^? or the ASCII code 127, which I can catch properly, however, I can't find the command to delete the ^? + last char that was typed, and Ideally, I would like to delete all the back up to the beginning of the prompt with backspace

Any ideas are greatly appreciated.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Jeffrey L. Roberts
  • 2,844
  • 5
  • 34
  • 69

1 Answers1

-1

I do not know a lot about curses, but if I understand you correctly one part of your question is that you do not know how to remove the last char of a string?

To pop the last char of a string:

st =  "abcdefghij"
st = st[:-1]

source

Maybe you can try something like this:

elif c == curses.KEY_DC or c == curses.KEY_BACKSPACE or c == 127:
            cur_line = cur_line[0:-1]
            stdscr.addstr(pos_type, (pos["x"] + pos_msg + len(cur_line)), " ".encode(code))        
            stdscr.addstr(pos_type, pos_con, "                     ".encode(code))

I do hope that this is helpful.

Community
  • 1
  • 1
Renier
  • 1,523
  • 4
  • 32
  • 60