pycontribs / ansi2html

Convert text with ansi color codes to HTML
GNU Lesser General Public License v3.0
387 stars 78 forks source link

Custom bg fg colors and css #203

Open CommanderPho opened 1 year ago

CommanderPho commented 1 year ago

I added custom_bg, custom_fg, and custom_content_css_dict parameters to Ansi2HTMLConverter to enable specifying custom background/foreground colors and css properties because I needed this functionality in my own project.

I believe this also satisfies the feature request mentioned here: #153

I've never used the CLI interface, so hopefully these properties don't interfere with that functionality (which I haven't tested or looked in to).

# Example with Custom CSS Overrides:
custom_css_content_dict = {'font-family':'"Lucida Console", "Courier New", monospace', 'font-size':'8px'} # produces css like: 'font-family: "Lucida Console", "Courier New", monospace; font-size: 8px;'
conv = Ansi2HTMLConverter(custom_bg='#FFFFFF', custom_fg='#220000', custom_content_css_dict=custom_css_content_dict)
ansi = " ".join(sys.stdin.readlines())
html = conv.convert(ansi)

Hope it's helpful to someone.

ssbarnea commented 10 months ago

@CommanderPho Can you please rebase?