4

I'm looking for a way to make the text that the user types in the console bold

input("Input your name: ")

If I type "John", I want it to show up as bold as I'm typing it, something like this

Input your name: John

Hardy
  • 43
  • 3
  • https://stackoverflow.com/questions/8924173/how-do-i-print-bold-text-in-python does this work? – yosukesabai Dec 01 '19 at 03:06
  • @yosukesabai It only works when you print things using print(), I want it to show up as bold right away when you type it in the console. Also I've already seen that, didn't help but thanks though – Hardy Dec 01 '19 at 03:12
  • 1
    Are you in linux? stty may be able to change your output to bold – oppressionslayer Dec 01 '19 at 03:21
  • I'm on windows. Also again, I'm not really looking for a way to print text in bold. I'm looking for a way to make the input text bold. But thank you – Hardy Dec 01 '19 at 03:26

1 Answers1

3

They are called ANSI escape sequence. Basically you output some special bytes to control how the terminal text looks. Try this:

x = input('Name: \u001b[1m')  # anything from here on will be BOLD

print('\u001b[0m', end='')  # anything from here on will be normal
print('Your input is:', x)

\u001b[1m tells the terminal to switch to bold text. \u001b[0m tells it to reset.

This page gives a good introduction to ANSI escape sequence.

Nick Lee
  • 5,169
  • 2
  • 25
  • 34
  • Thank you! I knew about ansi escape sequences but I didn't know you can use them this way – Hardy Dec 01 '19 at 03:29