[GH-ISSUE #1381] proposal: format filters #7433

Open
opened 2026-05-23 02:54:24 +01:00 by JakeStanger · 3 comments
Owner

Originally created by @lypwig on GitHub (Feb 17, 2026).
Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/1381

It could be interesting to be able to transform the values provided by some modules in formatting tokens.

For instance, let's suppose I want to show percents with unicode bars (" ▁▂▃▄▅▆▇██").
Percent values are used in several modules, so it will be tedious to write new modules from scratch just to display pretty bars.

I think this problem could be solved by what is called a filter by template engines.

First we define some filters:

filters:
  - name: bar
    path: dotfiles/bar.lua

... then we use them everywhere we want:

end:
  - type: volume
    format: "{icon} {percentage|bar}"
  - type: battery
    format: "{percentage|bar}"

Here, the lua code returns a function that takes a percent value in parameter (ie. 42), and return the formatted value (ie. ).

Some filters could also take a value in parameter, which is sometimes useful (for instance: {memory_percent|round(2)}), in this case the lua function takes 2 parameters.

Built-in filters could be provided for convenience (upper, round, etc).

Since a filter could also return nerd-font icons chars, I think this concept could allow many nice UI customization.

Built-in filters in the Twig template engine for reference: https://twig.symfony.com/doc/3.x/filters/index.html

Edit: Concerning the provided example, if the range filter described in #1388 is builtin, the format value could be {percentage|range(▁,▂,▃,▄,▅,▆,▇,█,█)}, without having to create a custom filter, but this one is still a good example.

Edit 2: It might be challenging but it could also be useful to allow to use cairo inside custom filters. For instance in the example above, bar could be a lua function that takes a percent number in input, and draws a custom gauge inline instead of text.

Edit 3: I found Askama, a light template engine written in rust that support filters, which could help here. I actually think that using a template engine for format strings might be a good idea.

Originally created by @lypwig on GitHub (Feb 17, 2026). Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/1381 It could be interesting to be able to transform the values provided by some modules in formatting tokens. For instance, let's suppose I want to show percents with unicode bars (" ▁▂▃▄▅▆▇██"). Percent values are used in several modules, so it will be tedious to write new modules from scratch just to display pretty bars. I think this problem could be solved by what is called a **filter** by template engines. First we define some filters: ```yml filters: - name: bar path: dotfiles/bar.lua ``` ... then we use them everywhere we want: ```yml end: - type: volume format: "{icon} {percentage|bar}" - type: battery format: "{percentage|bar}" ``` Here, the lua code returns a function that takes a percent value in parameter (ie. `42`), and return the formatted value (ie. `▅`). Some filters could also take a value in parameter, which is sometimes useful (for instance: `{memory_percent|round(2)}`), in this case the lua function takes 2 parameters. Built-in filters could be provided for convenience (upper, round, etc). Since a filter could also return nerd-font icons chars, I think this concept could allow many nice UI customization. Built-in filters in the Twig template engine for reference: https://twig.symfony.com/doc/3.x/filters/index.html Edit: Concerning the provided example, if the `range` filter described in #1388 is builtin, the format value could be `{percentage|range(▁,▂,▃,▄,▅,▆,▇,█,█)}`, without having to create a custom filter, but this one is still a good example. Edit 2: It might be challenging but it could also be useful to allow to use cairo inside custom filters. For instance in the example above, `bar` could be a lua function that takes a percent number in input, and draws a custom gauge inline instead of text. Edit 3: I found [Askama](https://askama.rs), a light template engine written in rust [that support filters](https://askama.rs/en/stable/filters.html), which could help here. I actually think that using a template engine for format strings might be a good idea.
Author
Owner

@lypwig commented on GitHub (Feb 19, 2026):

I think all this stuff represents a considerable amount of work and might be out of scope of this project, sorry for the inconvenience. Feel free to reopen if necessary.

<!-- gh-comment-id:3930390221 --> @lypwig commented on GitHub (Feb 19, 2026): I think all this stuff represents a considerable amount of work and might be out of scope of this project, sorry for the inconvenience. Feel free to reopen if necessary.
Author
Owner

@JakeStanger commented on GitHub (Feb 19, 2026):

I don't think this needs any external deps, or that this should support cairo (or anything other than String -> String but I think this does present a very powerful idea that could be used for formatting tokens.

<!-- gh-comment-id:3930547538 --> @JakeStanger commented on GitHub (Feb 19, 2026): I don't think this needs any external deps, or that this should support cairo (or anything other than `String -> String` but I think this does present a very powerful idea that could be used for formatting tokens.
Author
Owner

@lypwig commented on GitHub (Feb 25, 2026):

Some filters potentially useful could be the Pango filters, which put the text in tags or in a span element with properties used in the chained filters:

format: "hello|bold|italic" # <b><i>hello</i></b>
format: "hello|color('red')|size('24pt')" # <span color='red' size='24pt'>hello</span>
<!-- gh-comment-id:3961059565 --> @lypwig commented on GitHub (Feb 25, 2026): Some filters potentially useful could be the Pango filters, which put the text in tags or in a span element with properties used in the chained filters: ```yml format: "hello|bold|italic" # <b><i>hello</i></b> format: "hello|color('red')|size('24pt')" # <span color='red' size='24pt'>hello</span> ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
JakeStanger/ironbar#7433
No description provided.