neonrust / termic

TERMinal Interface (using) Cells
MIT License
0 stars 0 forks source link

In-band color & style syntax #10

Open neonrust opened 2 years ago

neonrust commented 2 years ago

To be able to control colors and style int the "string" content itself. Putting 'string' in quotes because the type might not be a string in the final implementation.

Essentially, just what escape sequences does for normal terminal output. However, we need full control over what is written to the terminal.

Might add support for "theme", so the style syntax may have color names and such baked in.

Example (completely fictional): \a|title|This is the \a+|red|title\a- text Where title is a color/style name (fg, bg and style is controlled by the theme) \a+ pushes a new style, and \a- pops it back to the previous style.

The advantage to this is terser user code. Also things like alignment combined with styling becomes much easier, which currently needs to be done manually (a measure() + multiple print()s).

neonrust commented 2 years ago

Could use a string literal (suffix) to be able to convert the string into another type, which allows transparent overloading of print(), I mean, in case we want to separate plain strings from strings containing in-band styling. Not sure if this is necessary though...

neonrust commented 2 years ago

The \a in the above examples was chosen because it is a control character that exists (compiler won't complain) but also not commonly used any more (terminal bell). Could also use \f (form feed), which might be a better association to style (i.e. "format"), as "a" is not easily associated...