This repository was archived by the owner on Oct 22, 2026. It is now read-only.
Repository navigation
Pretty print a policy - #222
Open
sanket1729 wants to merge 2 commits into
Open
sanket1729 wants to merge 2 commits into
sanket1729 wants to merge 2 commits into
Conversation
apoelstra
reviewed
Jan 13, 2021
| (x, y) => { | ||
| let red = "\x1b[0;31m"; | ||
| let nc = "\x1b[0m"; | ||
| let green = "\x1b[0;32m"; |
Member
There was a problem hiding this comment.
I think we need to come up with a different encoding scheme. It doesn't have to be pretty, we could provide a shellscript or something that converted it into a colorized version.
But using shell escape sequences means that we won't work on windows and are likely to confuse other command line tools.
sanket1729
added a commit
to sanket1729/rust-miniscript
that referenced
this pull request
Oct 1, 2021
e829434 Implemented Policy Diff (sanket1729) 4d23b79 Pretty print a policy (sanket1729) Pull request description: Adds methods to pretty print policies similar to directory tree printing in Linux. Prints diff in colors which highlights the differences between the two policies. Our representation of Semantic policies in only in Thresh, so we combine `or(pk,or(pk,pk))` into `thresh(1,pk,pk,pk)`. And so we use the latter in comparing two policies that complicate some of the implementation but is still fairly small. Top commit has no ACKs. Tree-SHA512: 8efd11b2c2582a4e26455ccb718d1ad2016ead3507746bd98a16240c7c72cf411df7fa01d817aee3a42c138b8ff7b887e7104d29d15f7a57a61620eee20a9d2b
apoelstra
reviewed
Nov 24, 2021
| } | ||
|
|
||
| /// Pretty Print a tree | ||
| pub fn pprint_tree(&self) { |
Member
There was a problem hiding this comment.
In 4d23b79:
Can we make this pub(crate)? I think we can come up with a much better API here and I'd rather not expose this one.
portlandhodl
added a commit
to portlandhodl/rust-miniscript
that referenced
this pull request
Aug 31, 2026
Modernized port of rust-bitcoin#222. Adds: - PolicyDiff::new(), which computes the syntactic difference between two normalized policies: children of same-shape thresholds that compare equal are matched up (position-independently) and the unmatched children of each side are returned. - Policy::to_tree_string(), which renders a policy in the style of the UNIX tree command. - Policy::to_diff_string(), which renders the difference between two policies, marking differing sub-policies with `- `/`+ ` instead of ANSI escape sequences. All functions are no_std-compatible and return Strings rather than printing to stdout. Co-authored-by: Sanket Kanjalkar <sanket1729@gmail.com>
Collaborator
|
My shot at this PR if anyone is interested. Though I'm having a hard time seeing a solid use case. |
Member
|
e829434 needs rebase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds methods to pretty print policies similar to directory tree printing in Linux. Prints diff in colors which highlights the differences between the two policies.
Our representation of Semantic policies in only in Thresh, so we combine
or(pk,or(pk,pk))intothresh(1,pk,pk,pk). And so we use the latter in comparing two policies that complicate some of the implementation but is still fairly small.