The function `maxRuneWidth` was using a flawed approach by only
evaluating strings based on each rune. The `uniseg` package provides a
more accurate method based on grapheme clusters.
This change switches over to the improved implementation which should
achieve better results when determining the maximum width of all
grapheme clusters in a string.
Signed-off-by: Michael Lorant <michael.lorant@nine.com.au>
The `padLeft` and `padRight` functions were nearly identical and could
benefit from being refactored to share common code.
A new function called `pad` was added that applies padding based on the
sign of the amount of padding needed. A positive value applies padding
to the right side while a negative value applies padding to the left
side.
Issue: #252
Signed-off-by: Michael Lorant <michael.lorant@nine.com.au>
* fix: renderer race condition
Guard accessing the underlying Termenv output behind a mutex. Multiple goroutines can set/get the dark background color causing a race condition.
* fix: cache color profile and background
* docs: add comment
Guard accessing the underlying Termenv output behind a mutex. Multiple goroutines can set/get the dark background color causing a race condition.
Needs: https://github.com/muesli/termenv/pull/146
Generally run-of-the-mill directives to disable magic number and exhaustive switches. Reasonings should be self explanatory while reading the code and comments, where applicable.
* feat: convert tabs to spaces with Style.TabWidth(int)
By default tabs will be converted to 4 spaces. To disable tab
conversion set Style.TabWidth(NoTabConversion).
Creating a _new_ global termenv output clashes with the default global
termenv output leading the terminal to block and freeze.
Share the default termenv output with the global default lipgloss renderer.
* docs(readme): add some context to the examples
* docs(readme): revert to render-function-based initial example
* docs(readme): drop extraneous stringer usage
* docs(readme): copyedits
* docs(renderer): minor documentation improvements
* docs(readme): edit renderer section to focus on custom outputs
* docs(readme): for now just use SetString to illustrate stringer
* docs(readme): re-add Ayman's clever stringer example
* docs(examples): tidy up wish example
* docs(examples): improve wish example
* docs(examples): session is an io.Writer
Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
* docs(examples): add missing pty argument
Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
* docs(example): remove extra space
* fix(examples): use termenv output
---------
Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Multiple lipgloss renderer instances can end up using the same default
termenv.Output. This leads to a race condition when manipulating the
ColorProfile concurrently.
We could mutex protect the standard output in termenv, but it feels like
a weak promise, as the rest of the Output wouldn't (and probably
shouldn't) get protected. Protecting it in lipgloss itself would require
a global lock however.
I can't come up with a proper use-case for this scenario, and therefore
we shift this responsibility to the user.