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

Add customized prompt for Rails console #50796

Merged
merged 1 commit into from Jan 19, 2024
Merged

Conversation

st0012
Copy link
Contributor

@st0012 st0012 commented Jan 18, 2024

Update

There were 2 more follow up PRs on this:

So the resulted prompt now looks like this instead:

Screenshot 2024-01-26 at 23 00 56

Motivation / Background

As discussed in #50770, Rails console's prompt is not easily distinguishable from normal IRB console. It also doesn't provide Rails-specific information to assist developers.

Closes #50770

Detail

  • A new IRB prompt called RAILS_PROMPT is added, which looks like:
    • dev:001> in development
    • prod:001> in production
    • test:001> in test
  • The RAILS_PROMPT is only selected when the user doesn't specify another custom prompt.

Additional information

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@byroot byroot changed the title Implement #50770 Add customized prompt for Rails console Jan 19, 2024
@st0012 st0012 force-pushed the implement-#50770 branch 2 times, most recently from c0f4e63 to eb8bf1f Compare January 19, 2024 16:43
Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

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

A nitpick for the CHANGELOG entry, but otherwise looks good to me! 👍

railties/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@byroot byroot left a comment

Choose a reason for hiding this comment

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

One last question, other than that LGTM.

Also please squash your commits into one.


if !Rails.env.local?
# Use env var here so users can override them with env var too
ENV["IRB_USE_AUTOCOMPLETE"] ||= "false"
Copy link
Member

Choose a reason for hiding this comment

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

Any way we could set this on the IRB config rather than in ENV? Not a big deal, but it's best not to mutate ENV if we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we set it with IRB.conf, users can't override it with IRB_USE_AUTOCOMPLETE=true due to IRB's initialization order. This probably won't affect many users, but because I mentioned it was overridable in the original changelog I think it'd be a breaking-change.

Copy link
Member

Choose a reason for hiding this comment

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

Can't you set it in IRB.conf under a unless ENV["IRB_USE_AUTOCOMPLETE"]. Reading the env is fine, it's changing it that I think would be best avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. But for that change I want to convert related unit tests into integration (application) tests too, which is a bit out of scope for this PR IMO. Do you mind if I open another PR for it?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's a pre-existing issue, so I don't mind. I'll merge once you squash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow up PR: #50814

Add Rails-specific IRB prompt

Update changelog
@byroot byroot merged commit 30cb7a6 into rails:main Jan 19, 2024
3 of 4 checks passed
@st0012 st0012 deleted the implement-#50770 branch January 19, 2024 19:12
st0012 added a commit to Shopify/rails that referenced this pull request Jan 23, 2024
The combination of red and blue is more color-blind friendly than red
and green.

Discussion: rails#50796 (comment)
st0012 added a commit to Shopify/rails that referenced this pull request Jan 24, 2024
The combination of red and blue is more color-blind friendly than red
and green.

Discussion: rails#50796 (comment)
@shloch
Copy link

shloch commented Jan 26, 2024

very useful feature thanks

when "test"
IRB::Color.colorize("test", [:GREEN])
when "production"
IRB::Color.colorize("prod", [:RED])
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be production?

Copy link
Contributor

Choose a reason for hiding this comment

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

seems prod is intended
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original discussion in #50770 decided to use abbreviations for development and production environments.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, same for dev, it should be development I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree, but you can raise that in the original issue.

Comment on lines +37 to +39
PROMPT_I: "#{env}:%03n> ",
PROMPT_S: "#{env}:%03n%l ",
PROMPT_C: "#{env}:%03n* ",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need line numbers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's removed in #50814

Copy link
Contributor

Choose a reason for hiding this comment

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

I see Screenshot 2024-01-26 at 15 24 54

viralpraxis pushed a commit to viralpraxis/rails that referenced this pull request Mar 24, 2024
The combination of red and blue is more color-blind friendly than red
and green.

Discussion: rails#50796 (comment)
fractaledmind pushed a commit to fractaledmind/rails that referenced this pull request May 13, 2024
The combination of red and blue is more color-blind friendly than red
and green.

Discussion: rails#50796 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request: rename Rails console as irr or something other than irb
8 participants