0

The following is my code that causes this error: TypeError: argument of type 'HTML' is not iterable

from prompt_toolkit import prompt
from prompt_toolkit.formatted_text import FormattedText, HTML

def get_input():
    prompt_text = [
        ("class:prompt-prefix", HTML('<ansired><b>{}</b></ansired>'.format('your input > '))),
        ("", '')
    ]
    placeholder = HTML('<b>enter `q` or `exit` to exit </b>')
    return prompt(prompt_text, placeholder=placeholder, default='').lower()

I tested and found that it is the prompt_text that introduces errors and I changed it to this:

prompt_text = HTML('<ansired><b>{}</b></ansired>'.format('your input \> '))
# escape > character or not does not matter, I found

It still does not work. How to fix this bug?

Lerner Zhang
  • 6,184
  • 2
  • 49
  • 66

1 Answers1

0

After some try and error I made it:

from prompt_toolkit import prompt
from prompt_toolkit.formatted_text import FormattedText, HTML
from prompt_toolkit.styles import Style

def get_input():
    prompt_style = Style.from_dict({
        'prompt': 'ansigreen bold',
        'input': '',
    })
    prompt_text = 'your input > '

    placeholder = HTML('<ansigray> enter `q` or `exit` to exit</ansigray>')
    return prompt(prompt_text, placeholder=placeholder, default='', style=prompt_style).lower()
Lerner Zhang
  • 6,184
  • 2
  • 49
  • 66