eww icon indicating copy to clipboard operation
eww copied to clipboard

[FEATURE] Add String Case Methods in Expressions

Open bbb651 opened this issue 2 years ago • 3 comments

Description of the requested feature

Add the following string case related functions to the expression language:

  • lower(string) -> string
  • upper(string) -> string I don't other conversions (uppercase first letter, snake case, camel case, etc) are that common and can be done with regex. Potentially also useful:
  • strip(string) -> string - (remove whitespace from either side of a string) maybe the default string widget and label should automatically strip their text?

Proposed configuration syntax

I'm assigning css classes based on the battery status from EWW_BATTERY.BAT0.status, which returns the status as a string starting with a capital letter, which isn't the convention for css classes. It would look like this:

(defwidget battery []
  (box :class "battery ${lower(EWW_BATTERY.BAT0.status)}"
  ...)
)

Additional context

All these operations are already possible with regex, but I feel like they're common enough to warrant dedicated methods.

bbb651 avatar Oct 21 '23 23:10 bbb651

hi dear Sounds good, i coded it but i had no time to test it can you please test it if it works i can open a pull request to the main String Methods

Lanpingner avatar Oct 23 '23 15:10 Lanpingner

hi dear Sounds good, i coded it but i had no time to test it can you please test it if it works i can open a pull request to the main String Methods

I tested it and it works great, I think trim is actually a better name than strip (I was looking at the python string methods names when thinking about the names) Demo

bbb651 avatar Oct 24 '23 04:10 bbb651

Okay, thanks i will rename it and open a pull request to the master later on today

Lanpingner avatar Oct 24 '23 08:10 Lanpingner