prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 717 forks source link

How to get transparent or no background color for bottom_toolbar #1767

Closed GhostOps77 closed 11 months ago

GhostOps77 commented 11 months ago

I'm just using the bottom_toolbar attribute in the PromptSession class to generate bottom bar, and by default, it displays text in white background.

I used HTML class to change the background color of the bottom toolbar, but I can't make the background to be transparent. (I mean, the text background should match the same as with my terminal). But as far as I've seen, I can't anything related to that at all.

So, is there anyway where I can get transparent bg for bottom_toolbar?

joouha commented 11 months ago

You need to pass a Style to your PromptSession defining the background-color for the bottom-toolbar class.

Have a look at the bottom-toolbar.py example.

The default bottom-toolbar class sets the reverse attribute, so you'll need to add noreverse to your style definition to remove the white background. Setting bg:default will make the background transparent.

from prompt_toolkit import prompt
from prompt_toolkit.styles import Style

style = Style.from_dict({"bottom-toolbar": "fg:lightblue bg:default noreverse"})
prompt("Input: ", bottom_toolbar="This is a toolbar", style=style)

image

GhostOps77 commented 11 months ago

Thanks! That worked! Closing this issue now