-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add Colorized, a new routes formatter #45241
base: main
Are you sure you want to change the base?
Conversation
I added `ActionDispatch::Routing::ConsoleFormatter::Colorized` that is a new routes formatter. Why a new formatter? The intention of this one is to add a different structure and colors to the actual `rails route` command. This formatter can be used by a new flag (`-C`) added on the `route` command.
end | ||
|
||
def colorize_path(path) | ||
path.gsub(/\/(:[a-z]*)/, "/#{YELLOW}\\1#{CLEAR}") |
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.
This doesn't fully cover a param. For example, your screenshot only highlights :inbound
of :inbound_email_id
. Parameters can also include numbers, underscores, capitals, and possibly other characters.
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 would love to see this merged 🙌 Such a nice detail. ❤️ |
def name_and_reqs(route) | ||
return route[:reqs] if route[:name].blank? | ||
|
||
"#{route[:name]}_path > #{route[:reqs]}" |
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.
Just a suggestion: I would swap >
with ->
, I think it's more clear.
"#{route[:name]}_path > #{route[:reqs]}" | |
"#{route[:name]}_path -> #{route[:reqs]}" |
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 like the suggestion but maybe we can use a Unicode character to represent the arrow, something like \u279C
that prints ➜
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.
Yeah, that would be even better.
Shared this on Twitter as well, but I think it'd be cool if we could separate PUT/PATCH from the actual POST requests for ease of readability. This is already doing it with DELETE, so it does make sense to me to have it as different categories. Great addition, it makes things better to easily parse 🎉 . |
Yeah, I've commonly seen orange used for the PUT/PATCH in other REST clients. |
I think instead of |
@skipkayhil By implementing what you're saying, The current So, is "colorized" an option, but then "sheet", "expanded" and "justified" are formats? Perhaps these screenshots should actually be |
FWIW, most CLI things I've seen that have a "colorized" option do not change any other formatting. They just add color codes when you colorize the output. Having a colorized flag that also rearranges the output is a bit nonstandard. That's why I'm thinking that "colorized" should apply to all formatters, and then if you want a new formatter for this justified output, that makes sense to me too. |
Yep, that all seems reasonable to me. If the implementation was changed to just colorize the existing format I think that would provide justification for a |
Can you perhaps expand on what's better about this layout, colours aside? At first look, to me, it seems to put all the emphasis on the path patterns, and makes it hard to match them up with their corresponding helpers. Most of the time I would expect users to want the opposite: for most purposes, one should be thinking in and using path helpers, and only occasionally need to deal with exactly which URLs they generate/match. |
Ok, I have been thinking about how to continue with this based on all the feedback received here and on Twitter. @matthewd I think this new layout is more natural to find what we're looking for in the output. From my experience, when we run the command, most of the time, the information we have is the path, and we're looking for the helper or controller/action or both. So, how we read from left to right, display the information we tend to have on the left side, and put the information we're looking for on the right side matches that. Again, this is from my POV and experience. Related to what @skipkayhil and @natematykiewicz were talking about, I agree that maybe the "colorize" concept should be a modifier of all formatters and not a formatter itself. I didn't want to jump directly and replace the default one ( So maybe the best approach to continue with this, as @natematykiewicz proposed, is to rename this formatter to Related to other comments for improvements that I received, the notes I took are:
|
Is this branch still alive? Would love to see this feature shipped. 🚀 Happy to help. |
would be great to see this PR merged on the main branch, what does it take to get there? Or there is no interest on the community to have this merged? Either way would be good to know where we stand. I think rails routes command needs a lift up and this is a step in the right direction. |
@Diogomartf Thanks for being interested on this. I couldn't come back here for some time, but I'll think what can be the best next steps here and continue working + communicating next week hopefully |
Really dig this! So much so that I think it should be the default and we use the flag to turn it off, when needed. |
Any reason to not use https://github.com/fazibear/colorize logic instead of defining this inline in routing inspector? Alternatively would it make sense to make "colorize" functionality into Active Support and use in here? IMHO it could be used for more outputs later. |
This doesn't warrant another gem dependency. If we can make it happen inline, great, otherwise, no. |
@dhh Thanks for the feedback, will solve conflicts, and make the changes this week. |
Summary
I added
ActionDispatch::Routing::ConsoleFormatter::Colorized
that is a new routes formatter.Why a new formatter?
The intention of this one is to add a different structure and colors to the actual
rails route
command.This formatter can be used by a new flag (
-C
) added on theroute
command.Before
After