Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/prompt_toolkit/shortcuts/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def display_placeholder() -> bool:
DynamicProcessor(lambda: merge_processors(self.input_processors or [])),
ConditionalProcessor(
AfterInput(lambda: self.placeholder),
filter=display_placeholder,
filter=display_placeholder & ~is_done,
),
]

Expand Down
40 changes: 39 additions & 1 deletion tests/test_shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
from __future__ import annotations

from prompt_toolkit.shortcuts import print_container
import pytest

from prompt_toolkit import renderer
from prompt_toolkit.formatted_text import ANSI
from prompt_toolkit.input.defaults import create_pipe_input
from prompt_toolkit.output import DummyOutput
from prompt_toolkit.shortcuts import PromptSession, print_container
from prompt_toolkit.shortcuts.prompt import _split_multiline_prompt
from prompt_toolkit.widgets import Frame, TextArea


@pytest.mark.parametrize(
"placeholder", ["Type a value", ANSI("\x1b[90mType a value\x1b[0m")]
)
@pytest.mark.parametrize("text", ["", "hello"])
def test_placeholder_is_hidden_after_accepting_input(mocker, placeholder, text):
draw = mocker.spy(renderer, "_output_screen_diff")
with create_pipe_input() as inp:
session = PromptSession(
"Question: ",
placeholder=placeholder,
input=inp,
output=DummyOutput(),
)
inp.send_text(text + "\r")
assert session.prompt() == text

# Inspect the actual screens sent to the output, including the final redraw.
screens = []
for call in draw.call_args_list:
screen, is_done = call.args[2], call.args[7]
content = "\n".join(
"".join(char.char for _, char in sorted(row.items())).rstrip()
for _, row in sorted(screen.data_buffer.items())
).rstrip()
screens.append((is_done, content))

assert any("Type a value" in content for is_done, content in screens if not is_done)
assert [content for is_done, content in screens if is_done] == [
("Question: " + text).rstrip()
]


def test_split_multiline_prompt():
# Test 1: no newlines:
tokens = [("class:testclass", "ab")]
Expand Down
Loading