Skip to content

Provide better ansi color codes. __doc__ strings are hard to read and not very "modern". #570

@MarcSkovMadsen

Description

@MarcSkovMadsen

The param __doc__ string is powerful. But it is hard to read due to the colors chosen.

The blue on a black background is especially hard to read. But also the red can also be hard to read. And the green just does not look modern.

As a consequence I am not really finding my self using the __doc__ string. Which makes it harder to use the HoloViz ecosystem. Especially hvplot and HoloViews where a lot of needed information is in the __doc__ string and not on their web sites or something you can find via intellisense in your editor.

Can you read the blue below? 😄

image

from panel.template.fast.list import FastListTemplate
import param
import panel as pn
import ansiconv

ACCENT_COLOR = "#0072B5"
pn.state.sizing_mode="stretch_width"

class ClassificationPlot(param.Parameterized):
    """The ClassificationPlot plots the output of a classification, i.e. the *labels*
    and their *score*.
    """
    output_json = param.List(doc="""
    The ouput of the classification""")
    options = param.Dict(constant=True, doc="""
    The configuration used to construct the plot""")
    color = param.Color(ACCENT_COLOR, doc="""
    The colors of the bars""")
    theme = param.Selector(default="default", objects=["default", "dark"], doc="""
    The theme, i.e. 'default' or 'dark'. This is automatically set from pn.state.session_args""")

plot = ClassificationPlot()
def to_html(txt):
    html = ansiconv.to_html(txt)
    css = ansiconv.base_css()

    html = f"""
    <style>{css}</style>
    <pre class="ansi_fore ansi_back">{html}</pre>
    """
    return pn.Column(pn.pane.HTML(html, width=1200, sizing_mode="fixed"), height=500, scroll=True)

card = pn.layout.Card(
    to_html(plot.__doc__), header="ClassificationPlot", sizing_mode="stretch_width", collapsed=False
)

FastListTemplate(
    title="ClassificationPlot", main=[card], accent_base_color=ACCENT_COLOR, header_background=ACCENT_COLOR
).servable()

Additional Context

We should be able to get a lot of inspiration from Rich. That output is very readable.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions