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

Custom formatting via config.toml #8

Merged
merged 10 commits into from
Aug 13, 2024

Conversation

dotaxis
Copy link
Contributor

@dotaxis dotaxis commented Jul 24, 2024

This allows customizing the output of spotifatius using the config.toml.

Includes {status} var which will print a play/pause unicode character depending on if the track is playing or paused.

Open to any suggestions on how to make it better, just let me know.

Also address #5

Copy link
Owner

@AndreasBackx AndreasBackx left a comment

Choose a reason for hiding this comment

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

This looks great, thank you! I think I primarily want to move the replace logic to the OutputFormatter. It would be nice if we additionally didn't hardcode the unicode icons. I've left a possible solution for that as well that would be relatively simple, even if a bit boilerplate-y.

Comment on lines 73 to 82
let status_icon = match status {
TrackStatus::Playing => " ",
TrackStatus::Paused => " ",
_ => "" // unable to get player state
};
output_format
.replace("{artist}", &artist)
.replace("{title}", &title)
.replace("{separator}", separator)
.replace("{status}", status_icon)
Copy link
Owner

Choose a reason for hiding this comment

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

Could you move this to OutputFormatter? If the replacing is done on all Output.text, we could make the other messages below configurable as well.

Additionally, the tooltip can be configurable.

You'll need to add a template_fields: HashMap<String, String> or something similar where you pass what needs replacing. Otherwise the OutputFormatter won't know.

Comment on lines +14 to +15
#[serde(default = "default_format")]
pub format: String,
Copy link
Owner

Choose a reason for hiding this comment

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

What do you think about having some extra formatting options?

pub struct TemplateConfigs {
	#[serde(default = "default_text_template")]
	pub text: TemplateConfig,
	#[serde(default = "default_tooltip_template")]
	pub tooltip: TemplateConfig,
}

pub struct TemplateConfig {
	pub default: String,
	pub playing: String,
	pub stopped: String,
	pub paused: String,
	pub added: String,
	pub removed: String,
}

This would allow configuration of icons and more so we do not hardcode those 2 unicode characters.

@dotaxis
Copy link
Contributor Author

dotaxis commented Jul 30, 2024

I'll take a look at this today and see what I can come up with.

@dotaxis
Copy link
Contributor Author

dotaxis commented Jul 30, 2024

I've done a bit more work on this. If you like the direction it's going I can add tooltip customization, but would rather wait to see if you want it refactored at all first.

I also started a review regarding the TrackStatus::Added/Removed triggers because I don't think they work.

@AndreasBackx
Copy link
Owner

Thank you! I'll try to give this a review this evening after work.

src/commands/output.rs Outdated Show resolved Hide resolved
src/commands/output.rs Outdated Show resolved Hide resolved
src/commands/output.rs Show resolved Hide resolved
README.md Show resolved Hide resolved
@AndreasBackx
Copy link
Owner

Forgot to leave a final comment with the review.

While I think the config can be improved, this is an improvement and I'm happy to extend it so it's better for you to use. I left some suggestions and with those applied, I think we can merge this.

Also please add an "Added" section to the Unreleased section of CHANGELOG.md. I'll put up a new version once it's merged and handle it appropriately. See https://keepachangelog.com/en/1.1.0/ for more info.

dotaxis and others added 2 commits August 1, 2024 09:08
Co-authored-by: Andreas Backx <[email protected]>
Apply suggestions from code review

Co-authored-by: Andreas Backx <[email protected]>
@AndreasBackx
Copy link
Owner

Also please add an "Added" section to the Unreleased section of CHANGELOG.md. I'll put up a new version once it's merged and handle it appropriately. See keepachangelog.com/en/1.1.0 for more info.

Should be good to merge after this.

@dotaxis
Copy link
Contributor Author

dotaxis commented Aug 1, 2024

Still waiting on some feedback on the Added/Removed logic not triggering

@AndreasBackx
Copy link
Owner

AndreasBackx commented Aug 1, 2024

@dotaxis I'm unsure if you're referring to feedback from me. You mentioned the below earlier but I'm not sure what you mean with that review.

I also started a review regarding the TrackStatus::Added/Removed triggers because I don't think they work.

Let me know if you need any of my help.

src/commands/output.rs Show resolved Hide resolved
src/commands/output.rs Show resolved Hide resolved
src/commands/output.rs Outdated Show resolved Hide resolved
@dotaxis
Copy link
Contributor Author

dotaxis commented Aug 1, 2024

@dotaxis I'm unsure if you're referring to feedback from me. You mentioned the below earlier but I'm not sure what you mean with that review.

I also started a review regarding the TrackStatus::Added/Removed triggers because I don't think they work.

Let me know if you need any of my help.

I forgot to submit my review so only I could see it. Oops.

@dotaxis
Copy link
Contributor Author

dotaxis commented Aug 3, 2024

Also please add an "Added" section to the Unreleased section of CHANGELOG.md. I'll put up a new version once it's merged and handle it appropriately. See keepachangelog.com/en/1.1.0 for more info.

Should be good to merge after this.

Sorry for the delay, been busy all week. Will get this done over the weekend.

@AndreasBackx
Copy link
Owner

AndreasBackx commented Aug 3, 2024

No rush at all, take all the time you need. You're the primary user for it.

@dotaxis
Copy link
Contributor Author

dotaxis commented Aug 7, 2024

Okay, I added a line in the changelog. Let me know if you need anything else done.

Copy link
Owner

@AndreasBackx AndreasBackx left a comment

Choose a reason for hiding this comment

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

Thanks, though make sure to test that they work. 😅 It does not compile right now.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -25,6 +27,68 @@ pub struct OutputFormatter {
}

impl OutputFormatter {
pub fn format_output(&self, response: MonitorResponse, status: TrackStatus, output_format: &str) -> Output {
let text_template = &self.config.text_template;
if let Some(track) = response.track {
Copy link
Owner

Choose a reason for hiding this comment

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

You're not closing this properly:

error: unexpected closing delimiter: `}`
   --> src/commands/output.rs:120:1
    |
42  |                 (Some(artist), Some(title)) => {
    |                                                - this delimiter might not be properly closed...
...
53  |                     };
    |                     - ...as it matches this but it has different indentation
...
120 | }
    | ^ unexpected closing delimiter

error: could not compile `spotifatius` (bin "spotifatius") due to 1 previous error

@dotaxis
Copy link
Contributor Author

dotaxis commented Aug 13, 2024

There was an extra closing brace in the change you requested on line 52.

@AndreasBackx AndreasBackx merged commit 945a0c4 into AndreasBackx:main Aug 13, 2024
@AndreasBackx
Copy link
Owner

Thanks again! It might take me some time to create a new version however. You should be able to use it yourself in the meantime however.

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