Commit Graph

75 Commits

Author SHA1 Message Date
Ayman Bagabas
2434fdaf07
fix: combining both conditional and unconditional wrapping (#275)
* feat: switch to term/ansi for text manipulation

Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: https://github.com/muesli/reflow/pull/71
Fixes: https://github.com/charmbracelet/lipgloss/issues/258
Fixes: https://github.com/charmbracelet/lipgloss/issues/220

* fix: combining both conditional and unconditional wrapping

Uses `ansi.SmartWrap` https://github.com/charmbracelet/x/pull/57

Fixes: https://github.com/muesli/reflow/issues/43

* chore: update deps

* Update get.go
2024-03-29 15:14:02 -04:00
Ayman Bagabas
f6f93348b0
feat: switch to term/ansi for text manipulation (#268)
* feat: switch to term/ansi for text manipulation

Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: https://github.com/muesli/reflow/pull/71
Fixes: https://github.com/charmbracelet/lipgloss/issues/258
Fixes: https://github.com/charmbracelet/lipgloss/issues/220

* Update get.go
2024-03-29 15:05:18 -04:00
Christian Rocha
b71dd12664 fix: transform shouldn't operate on ANSI sequences 2024-03-22 16:19:39 -04:00
Maas Lalani
d760238dd2
fix(style): possible nil panic (#245) 2024-03-15 10:56:32 -04:00
Michael Lorant
92946d34c2
chore: refactor padding functions (#254)
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>
2024-01-30 22:18:35 -05:00
Michael Lorant
04def9df3e
fix: the empty string can have padding on the right (#253)
An empty string could not have padding applied on the right side.

Issue: #252

Signed-off-by: Michael Lorant <michael.lorant@nine.com.au>
2024-01-30 17:38:39 -05:00
Christian Rocha
d354842a40
feat: Style.Transform for altering strings at render time (#232)
* feat: Style.Transform for altering strings at render time

* feat: add `UnsetTransform`

---------

Co-authored-by: Maas Lalani <maas@lalani.dev>
2023-11-27 14:33:38 -05:00
Ayman Bagabas
ac8231edce
fix: renderer race condition (#210)
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
2023-08-01 08:23:15 -04:00
Christian Rocha
01248034d0
chore(lint): add various nolint directives (#206)
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.
2023-07-24 11:50:04 -04:00
Christian Rocha
df8b3fa1f2
feat: convert tabs to spaces with Style.TabWidth(int) (#204)
* 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).
2023-07-24 11:22:48 -04:00
Ayman Bagabas
7f47f0b5e0 fix(renderer): use termenv default renderer
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.
2023-03-09 19:38:42 +01:00
Ayman Bagabas
c5382b35ef ref(renderer): change renderer impl 2023-03-08 09:54:27 -08:00
Ayman Bagabas
60d090659b feat(opts): use style options 2023-02-09 11:59:54 -05:00
Ayman Bagabas
29a309cde1 fix: renderer nil check 2023-02-09 11:59:54 -05:00
Ayman Bagabas
b9c2626fe7 feat(renderer): use style renderer
lipgloss.Style now takes a renderer instance to be used to detect styles
and colors based on its termenv.Output and terminal
2023-02-09 11:59:54 -05:00
Ayman Bagabas
31ab45f810 feat: instantiate lipgloss renderers
* Use lipgloss instances instead of a singleton global instance
* Deprecate (s Style).Render & (s Style).String
* Deprecate the Stringer interface
* Update README and godocs
* Update example
2023-02-09 11:59:54 -05:00
Carlos A Becker
f754c404f6 fix: reduce dependencies
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2023-02-09 11:59:54 -05:00
nervo
1c1240fd65
docs: fix various typos (#156) 2022-11-08 10:55:11 +01:00
Will Winder
3dd9f0bfb8 docs: minor fixes to comments 2022-10-15 15:40:38 -04:00
Maas Lalani
9852bb3017 feat: VerticalAlign
Add VerticalAlign, UnsetVerticalAlign, etc...
2022-09-06 14:11:09 -04:00
Ismael Padilla
e8297c491f Use ReplaceAll instead of Replace with n=-1 2022-07-14 23:03:04 +02:00
Brandon Fulljames
6b5dc18b3b Clarify Inherit comment 2022-03-04 12:27:20 -05:00
Dusan Gligoric
74e01f672d remove repeating code 2022-02-25 14:34:10 -05:00
Dusan Gligoric
75c95df92d dont overwrite background when inheriting 2022-02-25 14:34:10 -05:00
Christian Rocha
514fa059f3 Fix and generally improve various doc comments 2022-02-14 11:43:23 -05:00
Dusan Gligoric
0a77f6374d
Add Value method (#66) 2022-02-14 15:57:02 +01:00
Christian Rocha
4f0d448967 Force-wrap strings that run wider than the width 2021-09-03 10:20:33 -04:00
Christian Rocha
2b27307e58 Short circuit rendering if no style rules are set 2021-04-12 18:34:48 -04:00
Christian Rocha
bb42143109 Remove 'Color' suffix from border FG/BG API methods
This makes the border API better match the rest of the API. Also, the
'Color' part is implicit.
2021-04-07 12:23:36 -04:00
Christian Rocha
874349bbec Don't enable ANSI in cmd.exe until absolutely necessary 2021-04-06 11:39:01 -04:00
Kiyon
cb8ec749fe Use the same receiver name 2021-04-06 08:25:18 +02:00
Kiyon
3cb36e5bd1 Cleanup: fix a typo and remove a redundant line 2021-04-06 08:24:41 +02:00
Christian Rocha
3b2c9574ca
Remove the gaps and add the periods that the linter wants 2021-04-02 10:22:28 -04:00
Christian Rocha
31b52762a4
Style.Inline() now skips over padding, margins and borders entirely 2021-03-31 09:55:21 -04:00
Christian Rocha
34d6f0c73b
Make map before inheriting 2021-03-30 22:15:28 -04:00
Christian Rocha
cb8b96556e
Margins inherit background color 2021-03-30 22:15:28 -04:00
Christian Rocha
9b77861080
Style.Inherit should return a style 2021-03-30 22:15:28 -04:00
Christian Rocha
f74e4b84cb
Correct height measurement in Style.Render() 2021-03-30 22:15:28 -04:00
Christian Rocha
619b74ed87
Apply border before applying margins 2021-03-30 13:06:15 -04:00
Christian Rocha
73f6cab6ac
Option to set whitespace color in place functions + whitespace renderer 2021-03-26 15:57:47 -04:00
Christian Rocha
25d9c64aa9
Remove an unused const 2021-03-26 14:18:50 -04:00
Christian Rocha
5b43b10fd6
Add utility for horizontally and vertically placing blocks in whitespace 2021-03-26 13:35:48 -04:00
Christian Rocha
a47a89f4ae
Remove setting for underlining and striking whitespace 2021-03-26 10:36:23 -04:00
Christian Rocha
a3ab90a71c
Remove setting for not drawing trailing spaces 2021-03-26 09:30:54 -04:00
Christian Rocha
7739cea82a
Apply border after adding padding 2021-03-25 21:56:41 -04:00
Christian Rocha
d7bd9ebc4f
Borders are back 2021-03-25 20:43:40 -04:00
Christian Rocha
642c2c5310
Set width and alignment on single lines too 2021-03-24 16:42:34 -04:00
Christian Rocha
942108239f
Width enforces a minimum width 2021-03-24 16:34:03 -04:00
Christian Rocha
7b5208a1cd
Add Height and MaxHeight properties 2021-03-24 14:42:45 -04:00
Christian Rocha
acd9df30a7
Change margin and padding APIs to closer match CSS 2021-03-24 13:55:43 -04:00