[GH-ISSUE #34] Support for modules embedding in Custom #8456

Closed
opened 2026-05-23 03:52:12 +01:00 by JakeStanger · 10 comments
Owner

Originally created by @JustSimplyKyle on GitHub (Nov 6, 2022).
Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/34

From what I've observed, you can only put Widget in the Custom modules, I wish you can put modules (e.g. script) in the custom modules.
I want this cause I want to do retractable modules

Originally created by @JustSimplyKyle on GitHub (Nov 6, 2022). Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/34 From what I've observed, you can only put `Widget` in the Custom modules, I wish you can put modules (e.g. `script`) in the custom modules. I want this cause I want to do retractable modules
Author
Owner

@JakeStanger commented on GitHub (Nov 6, 2022):

Hm, this could be quite complex to do. I could certainly replicate the script module behaviour inside without much difficulty, but I'm not sure about nesting the actual modules.

Are there module types other than script you want to be able to do this with?


I guess at a higher level, the question is more "what exactly are you trying to achieve?" as it might be there's a better way of going about it.

<!-- gh-comment-id:1304781815 --> @JakeStanger commented on GitHub (Nov 6, 2022): Hm, this could be quite complex to do. I could certainly replicate the `script` module behaviour inside without much difficulty, but I'm not sure about nesting the actual modules. Are there module types other than `script` you want to be able to do this with? --- I guess at a higher level, the question is more "what exactly are you trying to achieve?" as it might be there's a better way of going about it.
Author
Owner

@JustSimplyKyle commented on GitHub (Nov 6, 2022):

Currently, I only need script.

https://user-images.githubusercontent.com/68589851/200174343-d0a23907-3adc-4204-a642-c4f3dc5dd7f4.mp4

This is what I hope to achieve, "retractable" modules(this is in waybar)
Its config is like this
image
custom/ss and custom/expand_sound etc. are all scripts that will check the state of whether it's expanded or not, if it's expanded display something, if not, display nothing.
This is rather cumbersome to script.
Although now that I think of it, embedding it wouldn't make it easier

<!-- gh-comment-id:1304805580 --> @JustSimplyKyle commented on GitHub (Nov 6, 2022): Currently, I only need `script`. https://user-images.githubusercontent.com/68589851/200174343-d0a23907-3adc-4204-a642-c4f3dc5dd7f4.mp4 This is what I hope to achieve, "retractable" modules(this is in waybar) Its config is like this ![image](https://user-images.githubusercontent.com/68589851/200174644-3a302dbc-622c-4189-94b7-6b304bc433d6.png) `custom/ss` and `custom/expand_sound` etc. are all scripts that will check the state of whether it's expanded or not, if it's expanded display something, if not, display nothing. This is rather cumbersome to script. Although now that I think of it, embedding it wouldn't make it easier
Author
Owner

@JakeStanger commented on GitHub (Nov 6, 2022):

It looks like your video failed to upload properly, but I think I get the gist.

There's a couple of ideas I've got that might help with this:

  • To custom, add the ability to run polling/watching scripts using the existing syntax. I'm undecided on the syntax, but it'd either use the existing bang ! or colon format and be something like label = "poll:5000:/path/to/script". This would allow the module to display dynamic content, which would be super powerful.
  • To all modules, add a config option like show-if that evaluates some shell command/script and only shows the module if it receives exit code 0. If not set, the module would always show. This should lift some of the logic out of your scripts and into the bar.

Let me know what you think or if you have any other suggestions

<!-- gh-comment-id:1304861416 --> @JakeStanger commented on GitHub (Nov 6, 2022): It looks like your video failed to upload properly, but I think I get the gist. There's a couple of ideas I've got that might help with this: - To `custom`, add the ability to run polling/watching scripts using the existing syntax. I'm undecided on the syntax, but it'd either use the existing bang `!` or colon format and be something *like* `label = "poll:5000:/path/to/script"`. This would allow the module to display dynamic content, which would be super powerful. - To all modules, add a config option like `show-if` that evaluates some shell command/script and only shows the module if it receives exit code 0. If not set, the module would always show. This should lift some of the logic out of your scripts and into the bar. Let me know what you think or if you have any other suggestions
Author
Owner

@JustSimplyKyle commented on GitHub (Nov 7, 2022):

Yeah, the show-if would be very helpful!
I think I'll personally would prefer the colon syntax

<!-- gh-comment-id:1305341408 --> @JustSimplyKyle commented on GitHub (Nov 7, 2022): Yeah, the `show-if` would be very helpful! I think I'll personally would prefer the colon syntax
Author
Owner

@JakeStanger commented on GitHub (Nov 20, 2022):

Okay I've got an implementation I think I'm happy with up and running, so I'll just need to tidy up and should have something pushed into master in the next few days.

Across the board, there is now a universal 'script' syntax. The places this can be utilised will definitely expand with time, and I still need to standardise the actual script module to be parallel. This comes in two flavours:

  1. As an object:
$clock = {
  type = "clock"
  show-if.cmd = "exit 0"
  show-if.interval = 500
}

You can create an object with the cmd key and optionally the interval and mode keys.

  1. As a string:
$clock = {
  type = "clock"
  show-if = "500:exit 0"
}

You can pass a string containing the command. This can optionally start with the interval and/or mode separated by colons. In cases where scripts are embedded into strings, you must use this syntax and not the object syntax.

I've got two new features that will make use of this syntax:

The first is the previously mentioned show-if command. This takes the exit status of a polling script and shows/hides the module accordingly. Because it relies on the exit status, watch mode is not supported here and the script will always be created as polling regardless of input.

The second is inside the custom module, where you can now embed scripts inside label values however you like. This allows you to include arbitrary snippets of text or multiple scripts easily. Anything inside {{double braces} is executed. Both polling and watch mode are supported here.

{ type = "label" name = "uptime" label = "Uptime: {{30000:uptime -p | cut -d ' ' -f2-}}" }

Let me know what you think! Now's a good time to add/remove/change anything before I tidy up the code & push it up.

<!-- gh-comment-id:1321238649 --> @JakeStanger commented on GitHub (Nov 20, 2022): Okay I've got an implementation I think I'm happy with up and running, so I'll just need to tidy up and should have something pushed into master in the next few days. Across the board, there is now a universal 'script' syntax. The places this can be utilised will definitely expand with time, and I still need to standardise the actual `script` module to be parallel. This comes in two flavours: 1. As an object: ```corn $clock = { type = "clock" show-if.cmd = "exit 0" show-if.interval = 500 } ``` You can create an object with the `cmd` key and optionally the `interval` and `mode` keys. 2. As a string: ```corn $clock = { type = "clock" show-if = "500:exit 0" } ``` You can pass a string containing the command. This can optionally start with the interval and/or mode separated by colons. In cases where scripts are embedded into strings, you must use this syntax and not the object syntax. I've got two new features that will make use of this syntax: The first is the previously mentioned `show-if` command. This takes the exit status of a **polling** script and shows/hides the module accordingly. Because it relies on the exit status, watch mode is not supported here and the script will always be created as polling regardless of input. The second is inside the custom module, where you can now embed scripts inside label values however you like. This allows you to include arbitrary snippets of text or multiple scripts easily. Anything inside `{{double braces}` is executed. Both polling and watch mode are supported here. ```corn { type = "label" name = "uptime" label = "Uptime: {{30000:uptime -p | cut -d ' ' -f2-}}" } ``` Let me know what you think! Now's a good time to add/remove/change anything before I tidy up the code & push it up.
Author
Owner

@JustSimplyKyle commented on GitHub (Nov 21, 2022):

Seems pretty good.
I have one question tho
show-if = "500:my_script"does this mean: "Show the label if the exit code of my_script is 0?

<!-- gh-comment-id:1321774216 --> @JustSimplyKyle commented on GitHub (Nov 21, 2022): Seems pretty good. I have one question tho `show-if = "500:my_script"`does this mean: "Show the label if the exit code of `my_script` is 0?
Author
Owner

@JakeStanger commented on GitHub (Nov 21, 2022):

Yep, exactly that :) I think that's the most unix-y approach to it, and means you can use things like [

<!-- gh-comment-id:1321779411 --> @JakeStanger commented on GitHub (Nov 21, 2022): Yep, exactly that :) I think that's the most unix-y approach to it, and means you can use things like `[`
Author
Owner

@JakeStanger commented on GitHub (Nov 28, 2022):

Couple of updates just pushed up should mean you can do what you want to do without too much difficulty now. Let me know if this doesn't resolve it for you & I'll re-open.

<!-- gh-comment-id:1329843042 --> @JakeStanger commented on GitHub (Nov 28, 2022): Couple of updates just pushed up should mean you can do what you want to do without too much difficulty now. Let me know if this doesn't resolve it for you & I'll re-open.
Author
Owner

@JustSimplyKyle commented on GitHub (Nov 29, 2022):

Pretty good! Successfully remade the expand action with minimal amount of scripting.
Although one thing, is it possible to combine these three "modules"(it is just three different scripts) into one?
image

<!-- gh-comment-id:1330694936 --> @JustSimplyKyle commented on GitHub (Nov 29, 2022): Pretty good! Successfully remade the expand action with minimal amount of scripting. Although one thing, is it possible to combine these three "modules"(it is just three different scripts) into one? ![image](https://user-images.githubusercontent.com/68589851/204549006-847a3937-e890-48ce-a17a-15dc2a9e7e9d.png)
Author
Owner

@JakeStanger commented on GitHub (Nov 29, 2022):

Not currently. I've considered adding a "spread" operator into Corn that would allow you to merge objects/arrays that would allow for this, but nothing concrete as of yet.

<!-- gh-comment-id:1331063255 --> @JakeStanger commented on GitHub (Nov 29, 2022): Not currently. I've considered adding a "spread" operator into Corn that would allow you to merge objects/arrays that would allow for this, but nothing concrete as of yet.
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#8456
No description provided.