Skip to content
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

Add :escape property to label #1248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

silicon-salamander
Copy link

Description

Add :escape property to the label widget in order to disable interpreting escape sequences. Defaults to true.

Usage

(label :class "window-title"
  :escape false
  :text {title} ; could contain any text that I don't want interpreted
)

Showcase

With :escape true the window title on my bar shows newlines and expands the bar.
screenshot_2024-12-17_12:12:51

With :escape false the window title correctly displays \n as literal text.
screenshot_2024-12-17_12:12:25

Additional Notes

I'm not sure if I need to add documentation anywhere else. Let me know if I do.

Checklist

Please make sure you can check all the boxes that apply to this PR.

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing

Copy link
Contributor

@w-lfchen w-lfchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think a good thing to add to this pr would be switching to a maintained escaping crate such as unescaper (haven't really looked for more).

i started working on improving the escaping logic a while ago since in some cases, things need to be escaped twice, which shouldn't be necessary, but these days i don't really have enough free time to finish my draft.

if you want to, you can look into this as well, but it's probably out of scope for this pr

@silicon-salamander
Copy link
Author

Hmm yeah, I didn't realize there were wider issues. I guess one of the lexers needs to be modified to work better in combination with unescape so that you don't need to do \\n.

I think the ideal fix would be to only have string literals in your config file automatically "unescaped" and then have an escape() function in simplexpr so you can optionally "unescape" text that is coming in through a dynamic variable.

This PR is just a bandage, but not really fixing the root cause. I barely know any rust, so I would need to learn more to be able to fix these issues. I'm definitely interested in trying, it just might take a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants