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

feat: configurable threshold and colorful output #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

wathenjiang
Copy link

The time of warn threshlod may be configurable and colorable.

@wathenjiang
Copy link
Author

Please run the color example to see more details.

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! May run cargo fmt and cargo clippy to pass the checks.

Copy link
Member

Choose a reason for hiding this comment

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

Would you please remove this file?

Copy link
Author

@wathenjiang wathenjiang Jul 10, 2023

Choose a reason for hiding this comment

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

Yeah. I would do this, sorry for irrelevant file.

src/registry.rs Outdated Show resolved Hide resolved
src/registry.rs Outdated Show resolved Hide resolved
@@ -29,13 +30,23 @@ use crate::Span;
#[builder(default)]
pub struct Config {
/// Whether to include the **verbose** span in the await-tree.
verbose: bool,
pub verbose: bool,
Copy link
Member

Choose a reason for hiding this comment

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

We may keep these fields private (or pub(crate)) and use ConfigBuilder to construct a Config.

Copy link
Author

Choose a reason for hiding this comment

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

We may keep these fields private (or pub(crate)) and use ConfigBuilder to construct a Config.

Current config is simple, only three fields, but the disign pattern is up to you. Maybe the current version is enough.

Copy link
Member

Choose a reason for hiding this comment

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

We already have ConfigBuilder now (by deriving Builder) so there's no extra effort required. :)

Comment on lines +62 to +67

/// Whether to coloring the terminal
colored: bool,

/// if the time of execution is beyond it, warn it
warn_threshold: time::Duration,
Copy link
Member

Choose a reason for hiding this comment

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

What about directly storing a Config here?

Copy link
Author

Choose a reason for hiding this comment

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

What about directly storing a Config here?

If put Config here, the field verbose is not used by context.

Copy link
Member

@BugenZhao BugenZhao Jul 10, 2023

Choose a reason for hiding this comment

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

Yeah, you're right. So I'm considering whether colored and warn_threshold should be properties of tree formatting, instead of the tree or the registry. 🤔 For example, we have...

struct FormatConfig {
  colored: bool,
  warn_threshold: time::Duration,
}

pub struct FormatTree<'a> {
  tree: &'a Tree,
  config: FormatConfig
}

impl Display for FormatTree<'_> { .. }

impl Tree {
  pub fn display(&self, config: FormatConfig) -> FormatTree<'_> { .. }
}

impl Display for Tree { /* delegate to `self.display(FormatConfig::default()).fmt(f)` */ }

Copy link
Author

Choose a reason for hiding this comment

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

Yes, It could be done this way.

@wathenjiang
Copy link
Author

Thanks for your contribution! May run cargo fmt and cargo clippy to pass the checks.

Made it~

@wathenjiang
Copy link
Author

wathenjiang commented Jul 23, 2023

Hey, what is the current progress of this MR? Is there something need to do from my side?

@@ -19,6 +19,7 @@ parking_lot = "0.12"
pin-project = "1"
tokio = { version = "1", features = ["rt"] }
tracing = "0.1"
colored = "2"
Copy link

Choose a reason for hiding this comment

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

Maybe we should hide this under a feature?

Copy link
Member

Choose a reason for hiding this comment

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

Both LGTM :)

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, both LGTM. They are about the balance between performance and convenience.

@@ -19,6 +19,7 @@ parking_lot = "0.12"
pin-project = "1"
tokio = { version = "1", features = ["rt"] }
tracing = "0.1"
colored = "2"
Copy link
Member

Choose a reason for hiding this comment

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

Both LGTM :)

@BugenZhao BugenZhao changed the title Feature/colour feat: configurable threshold and colorful output Jul 27, 2023
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.

3 participants