New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make edit:styled
more high-level and allow nesting
#520
Comments
Very nice! |
The new built-ins as iplemented in #674 are awesome. A couple of comments from my initial testing:
|
When I get around it I will write documentation about the two new builtins. |
If the end goal is to make colors appear the same in the terminal and via CSS it may make sense to not allow raw numbers, but instead use color names. Unfortunately the color namespace is kind of broken: |
@fehnomenal thanks for your response (and of course, for the implementation of
|
As there are currently only 16 valid colors I would put their names into a list and index into it: |
Fair enough, but it seems like a step backwards to not allow full use of
256 colors...
…On Tue, May 29, 2018 at 2:50 PM, fehnomenal ***@***.***> wrote:
As there are currently only 16 valid colors I would put their names into a
list and index into it: styled foo $colors[(% $pid (count $colors))]. Of
course this will only result in 16 different colors but you could also
include the bg- variants.
Probably the end goal should be to internally use color.Color, map color
names to predefined values and let the displaying component choose how to
render individual colors.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#520 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AACAbIYBH-JxkujxBAh6HGJDa55eY6eoks5t3UQYgaJpZM4QxszX>
.
|
I am already working on it but there are some things needing discussion. I will soon open a new issue where we can focus on adding support for more colors. |
Since |
Right now,
edit:styled
is tied to the terminal: There is a one-to-one relationship (code) mapping the supported styles to ANSI color sequences ("\e[1;31m"
, where1;31
can be any semicolon-separated list of numbers), and it is possible to specify a number (or multiple numbers separated by semicolons) as the "style".This is an improvement over writing ANSI color sequences by hand, but it still has a few drawbacks:
It is tied to the terminal. In future, Elvish will support a web frontend where ANSI color sequences are not directly supported. It is possible to parse and convert them to CSS, but that is backwards. If we start with a high-level internal format, it can then support multiple presentations, including both ANSI color sequences and CSS.
It does not support nesting. For instance, the ANSI color sequence for reverse video is
"\e[7m"
. Two inverses cancel each other: soecho (edit:styled (edit:styled lorem inverse) inverse)
should printlorem
in normal style. However, without knowing the semantics of those different styles, it is not possible to compose them. Again, we can hack composing into the current implementation, but it is cleaner to do it from the source by having a semantics-based internal format.Another minor thing is that since this function is useful outside editors, it is appropriate to put it in the builtin namespace, making the constructor
styled
.Current design is as follows:
A styled text is internally a list of styled segments; a segment is a string, combined with several attributes:
fg-color
,bg-color
,inverse
,bold
, etc. It is possible to construct a segment withstyled-segment
, specifying the attributes as options, e.g.styled-segment lorem &fg-color=red &bold=$true
. If the argument is already a styled segment,styled-segment
copies it and modifies the specified attributes. Attributes of styled segments can be accessed like map elements, e.g.$seg[bold]
.It is possible to concatenate plain strings, styled segments and styled texts together: they will form a styled text that combines them, e.g.
echo (styled-segment lorem &fg-color=red)(styled-segment ipsum &inverse=$true)foobar
. No implicit whitespace is inserted between concatenated elements.It is possible to apply style transformers to a piece of styled text. This uses the
styled
command, which accepts a plain string, a styled segment or styled text, and apply the transformer to all segments: e.g.echo (styled (styled-segment lorem &fg-color=red)" "(styled-segment ipsum &inverse=$true) inverse)
. Theinverse
transformer toggles theinverse
attribute, so that the result will be a red-and-inversedlorem
, an inverse space, and and a normalipsum
.A style transformer is simply a function that takes a styled segment and outputs another styled segment. For instance, the
inverse
transformer can be implemented as[seg]{ styled-segment $seg &inverse=(not $seg[inverse]) }
. The mapping from the name to the implementation is kept in$styled-transformer
. The default value implements all the styles supported by the currentedit:styled
implementation, likebold
,blue
,bg-blue
.In practice, this means that the user never has to use
styled-segment
, and the API ofstyled
is backwards compatible with the currentedit:styled
.The text was updated successfully, but these errors were encountered: