Fixed prompt sometimes not clearing.
This commit is contained in:
@@ -411,12 +411,19 @@ class Terminal(object):
|
|||||||
|
|
||||||
n_rows, n_cols = self.stdscr.getmaxyx()
|
n_rows, n_cols = self.stdscr.getmaxyx()
|
||||||
attr = curses.A_BOLD | Color.CYAN
|
attr = curses.A_BOLD | Color.CYAN
|
||||||
prompt = self.clean(prompt, n_cols - 1)
|
prompt = self.clean(prompt, n_cols-1)
|
||||||
window = self.stdscr.derwin(
|
|
||||||
1, n_cols - len(prompt), n_rows - 1, len(prompt))
|
# Create a new window to draw the text at the bottom of the screen,
|
||||||
window.attrset(attr)
|
# so we can erase it when we're done.
|
||||||
self.add_line(self.stdscr, prompt, n_rows-1, 0, attr)
|
prompt_win = curses.newwin(1, len(prompt)+1, n_rows-1, 0)
|
||||||
self.stdscr.refresh()
|
self.add_line(prompt_win, prompt, attr=attr)
|
||||||
|
prompt_win.refresh()
|
||||||
|
|
||||||
|
# Create a separate window for text input
|
||||||
|
input_win = curses.newwin(1, n_cols-len(prompt), n_rows-1, len(prompt))
|
||||||
|
input_win.attrset(attr)
|
||||||
|
input_win.refresh()
|
||||||
|
|
||||||
if key:
|
if key:
|
||||||
curses.curs_set(1)
|
curses.curs_set(1)
|
||||||
ch = self.getch()
|
ch = self.getch()
|
||||||
@@ -426,7 +433,15 @@ class Terminal(object):
|
|||||||
text = ch if ch != self.ESCAPE else None
|
text = ch if ch != self.ESCAPE else None
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
else:
|
else:
|
||||||
text = self.text_input(window)
|
text = self.text_input(input_win)
|
||||||
|
|
||||||
|
prompt_win.clear()
|
||||||
|
input_win.clear()
|
||||||
|
del prompt_win
|
||||||
|
del input_win
|
||||||
|
self.stdscr.touchwin()
|
||||||
|
self.stdscr.refresh()
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def prompt_y_or_n(self, prompt):
|
def prompt_y_or_n(self, prompt):
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ def test_prompt_input(terminal, stdscr, ascii):
|
|||||||
assert isinstance(terminal.prompt_input('hi'), six.text_type)
|
assert isinstance(terminal.prompt_input('hi'), six.text_type)
|
||||||
|
|
||||||
attr = Color.CYAN | curses.A_BOLD
|
attr = Color.CYAN | curses.A_BOLD
|
||||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
stdscr.subwin.addstr.assert_called_with(0, 0, 'hi'.encode('ascii'), attr)
|
||||||
assert window.nlines == 1
|
assert window.nlines == 1
|
||||||
assert window.ncols == 78
|
assert window.ncols == 78
|
||||||
|
|
||||||
@@ -236,25 +236,26 @@ def test_prompt_y_or_n(terminal, stdscr):
|
|||||||
|
|
||||||
stdscr.getch.side_effect = [ord('y'), ord('N'), terminal.ESCAPE, ord('a')]
|
stdscr.getch.side_effect = [ord('y'), ord('N'), terminal.ESCAPE, ord('a')]
|
||||||
attr = Color.CYAN | curses.A_BOLD
|
attr = Color.CYAN | curses.A_BOLD
|
||||||
|
text = 'hi'.encode('ascii')
|
||||||
|
|
||||||
# Press 'y'
|
# Press 'y'
|
||||||
assert terminal.prompt_y_or_n('hi')
|
assert terminal.prompt_y_or_n('hi')
|
||||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
stdscr.subwin.addstr.assert_called_with(0, 0, text, attr)
|
||||||
assert not curses.flash.called
|
assert not curses.flash.called
|
||||||
|
|
||||||
# Press 'N'
|
# Press 'N'
|
||||||
assert not terminal.prompt_y_or_n('hi')
|
assert not terminal.prompt_y_or_n('hi')
|
||||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
stdscr.subwin.addstr.assert_called_with(0, 0, text, attr)
|
||||||
assert not curses.flash.called
|
assert not curses.flash.called
|
||||||
|
|
||||||
# Press Esc
|
# Press Esc
|
||||||
assert not terminal.prompt_y_or_n('hi')
|
assert not terminal.prompt_y_or_n('hi')
|
||||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
stdscr.subwin.addstr.assert_called_with(0, 0, text, attr)
|
||||||
assert not curses.flash.called
|
assert not curses.flash.called
|
||||||
|
|
||||||
# Press an invalid key
|
# Press an invalid key
|
||||||
assert not terminal.prompt_y_or_n('hi')
|
assert not terminal.prompt_y_or_n('hi')
|
||||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
stdscr.subwin.addstr.assert_called_with(0, 0, text, attr)
|
||||||
assert curses.flash.called
|
assert curses.flash.called
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user