Skip to content
erikrose edited this page Feb 1, 2012 · 1 revision

Here are some alternative syntaxes I considered during Blessings' design, here for posterity.

term.red(term.bold('hi'))  # needs a little semaphore (which won't work, because the inner stuff gets called first). Would have nonworking nest orders, like term.red(term.bold('hi') + 'actually not still red because bold called normal')

term.color('hi', 'red', 'on_green')

term.red_on_green('hi')  # how to do bold with it, which clears everything when it resets?

term.format('hi', 'red', 'on_green', 'bold')  # would set it to normal afterward

'  {grey + bold}%(editor)s +%(line)-' + str(line_width) + 's %(file)s{plain}'
'{purple}%(function)s{unpurple}\n')

('  {t.grey}{t.bold}%(editor)s +%(line)-' + str(line_width) + 's %(file)s{t.normal}'
 '{t.bright_magenta}%(function)s{t.normal}\n').format(t=term)

term.bold_white_on_green('o hai!')  # A fave. Writes normal at the end. But how do we let the user customize the colors on the CLI? Pretty damn well, as it turns out: just pass in bold__reverse__on_green. You can control attrs and color all at once! Then break down and use getattr. Impl can see if the attr is in {colors, formats, bg_colors}. If it isn't, see if it has _ in it. If so, take it apart. If any segment is "on", merge it with the seg to its right. Same for "bright". Be sure to document that these print sgr0 at the end--you can't nest them.
term.bold_grey('  %(editor)s +%(line)-' + str(line_width) + 's %(file)s') +  term.bright_magenta('%(function)s') + '\n'  # Not bad. Gets the {t.normal}s out of the string by making them implicit.
Clone this wiki locally