-
Notifications
You must be signed in to change notification settings - Fork 119
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
feat: bar component for scripted text #252
base: main
Are you sure you want to change the base?
Conversation
var output = outSb.ToString(); | ||
var json = Regex.Matches(output).Last(); // extract json block | ||
var result = JsonSerializer.Deserialize<Dictionary<string, object>>(json.Value); | ||
FormattedText = result.Aggregate(_baseConfig.Format, (state, item) => state.Replace($"{{{item.Key}}}", item.Value.ToString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there might be users who have scripts which just return strings instead of JSON.
to solve this, would it be possible to do label: "{output.coin} {output.price}"
for scripts where the output is JSON, and label: BTC price {output}
for scripts that simply output a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that returning json and doing formatting on the application side will be more convenient than parsing lables inside a script
I just want a few values from the script to use in the output
otherwise, you will have to return the finished string from the script and the format is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not 100% sure what to do about this. posted about it in the #contributing channel on discord
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do you want to return multiple value from cmd script?
echo value1 value2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in polybar, users would write a .sh
script and whatever it outputs is shown in the bar. so to remake your BTC example in polybar, a script would have to output eg "BTC: 22000"
. There is no support for multiple values.
A lot of glazewm users come from polybar, and a lot cli scripts out there don't output as JSON. So ideally we can figure out a solution that supports showing regular text output, as well as JSON.
It's hard to explain the idea i'm proposing, so i'll show a few examples:
- user has a script that outputs
"BTC: 22000"
, he can define a configlabel: "{output}"
- user has a script that outputs
"22000"
, he can define a configlabel: "BTC: {output}"
- user has a script that outputs
{ "price": "22000" }
, he can define a configlabel: "BTC: {output.price}"
- user has a script that outputs
{ "price": "22000", "token: "BTC" }
, he can define a configlabel: "{output.token}: {output.price}"
^ with this way, users can use scripts that output regular text, as well as JSON
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added output type
new config
|
and test this with compiled dotnet app
|
{ | ||
var updateInterval = TimeSpan.FromMilliseconds(_baseConfig.IntervalMs); | ||
TimerSub = Observable.Interval(updateInterval).Subscribe( _ => RunScript()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor can be simplified a bit by changing Init
:
private void Init()
{
_ = RunScript();
var updateInterval = TimeSpan.FromMilliseconds(_baseConfig.IntervalMs);
Observable.Interval(updateInterval)
.TakeUntil(_bus.Events.OfType<UserConfigReloadedEvent>())
.Subscribe(_ => RunScript());
}
var output = outSb.ToString(); | ||
var json = Regex.Matches(output).Last(); // extract json block | ||
var result = JsonSerializer.Deserialize<Dictionary<string, object>>(json.Value); | ||
FormattedText = result.Aggregate(_baseConfig.Format, (state, item) => state.Replace($"{{{item.Key}}}", item.Value.ToString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not 100% sure what to do about this. posted about it in the #contributing channel on discord
No description provided.