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

Basic command prompt #376

Merged
merged 6 commits into from
Jul 3, 2024
Merged

Basic command prompt #376

merged 6 commits into from
Jul 3, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Jun 22, 2024

This is part of #372. This PR only supports $PS1.

  • Stub the yash-prompt crate
  • Implement the Prompter input decorator
  • Construct a prompt string from the variable
  • Use the Prompter decorator

Summary by CodeRabbit

  • New Features

    • Introduced a new yash-prompt package for enhanced command prompt functionality.
    • Added prompt string expansion following POSIX standards.
  • Documentation

    • Added README.md and CHANGELOG.md for yash-prompt.
    • Included GNU General Public License (GPL) v3 for yash-prompt.
  • Refactor

    • Updated yash-cli to use yash-prompt for command prompt implementation.
    • Modified prepare_input function to conditionally apply the Prompter decorator.
  • Tests

    • Added comprehensive tests for yash-prompt functionalities.

@magicant magicant added the enhancement New feature or request label Jun 22, 2024
@magicant magicant added this to the 0.1.0 β2 milestone Jun 22, 2024
@magicant magicant self-assigned this Jun 22, 2024
Copy link

coderabbitai bot commented Jun 22, 2024

Walkthrough

The changes introduce a new crate, yash-prompt, for prompt strings following POSIX expansion standards. It adds build and test commands, updates several dependencies, implements new functionality for prompt handling, and integrates yash-prompt with yash-cli. The alterations include function signature updates, new modules, and modified imports to support prompt decoration in the interactive shell environment.

Changes

Files / Folders Summary of Changes
check-extra.sh Added build and test commands for yash-prompt.
check-msrv.sh Updated workspace members for testing yash-prompt.
yash-prompt/CHANGELOG.md Introduced initial changelog documentation for yash-prompt.
yash-prompt/Cargo.toml Defined package dependencies and configurations.
yash-prompt/LICENSE-GPL Added GPL v3 license document.
yash-prompt/README.md Introduced crate features, badges, and license info.
yash-prompt/src/expand_posix.rs Implemented POSIX prompt expansion with new function signature.
yash-prompt/src/lib.rs Added library entry point, exporting expand_posix and Prompter.
yash-prompt/src/prompter.rs Implemented Prompter decorator for displaying shell prompts.
yash-cli/Cargo.toml Added yash-prompt as a dependency.
yash-cli/src/startup.rs Conditional prompt decoration applied in prepare_input function.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant Prompter
    participant Env
    participant PosixExpander

    User->>CLI: Start interactive shell
    CLI->>Prompter: Apply prompt decorator
    Prompter->>Env: Retrieve prompt template ($PS1)
    Prompter->>PosixExpander: Expand POSIX prompt
    PosixExpander->>Prompter: Return expanded prompt
    Prompter->>CLI: Display prompt
    User->>CLI: Enter command
    CLI->>Prompter: Remove prompt decorator
    CLI->>Env: Execute command
    Env-->>CLI: Command result
    CLI-->>User: Output result
Loading

Possibly related issues

Poem

In the realm of shells so bright,
A prompt awakens, shining light,
With POSIX rules, it doth expand,
To greet each command at your hand.
In code it whispers, "Here I stand,"
Ready to serve in interactive land.
The future smiles at this prompt's command.

🐇💻✨

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

This commit adds the minimum code to show the default prompt. The prompt
is hardcoded to "$ " for now. The prompt is shown before reading the
input from the inner input.
yash-prompt/src/prompter.rs Outdated Show resolved Hide resolved
yash-prompt/src/prompter.rs Show resolved Hide resolved
@magicant magicant marked this pull request as ready for review July 2, 2024 16:32
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdda015 and bebdd66.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (9)
  • check-extra.sh (3 hunks)
  • check-msrv.sh (1 hunks)
  • yash-prompt/CHANGELOG.md (1 hunks)
  • yash-prompt/Cargo.toml (1 hunks)
  • yash-prompt/LICENSE-GPL (1 hunks)
  • yash-prompt/README.md (1 hunks)
  • yash-prompt/src/expand_posix.rs (1 hunks)
  • yash-prompt/src/lib.rs (1 hunks)
  • yash-prompt/src/prompter.rs (1 hunks)
Files skipped from review due to trivial changes (3)
  • check-extra.sh
  • yash-prompt/CHANGELOG.md
  • yash-prompt/README.md
Additional comments not posted (19)
yash-prompt/Cargo.toml (3)

1-14: LGTM!

The package metadata is complete and correct.


16-20: LGTM!

The dependencies are correctly specified.


22-24: LGTM!

The dev-dependencies are correctly specified.

yash-prompt/src/lib.rs (3)

1-15: LGTM!

The license header is correctly specified.


21-21: LGTM!

The module imports are correctly specified.

Also applies to: 26-26


22-22: LGTM!

The module exports are correctly specified.

Also applies to: 27-27

check-msrv.sh (3)

Line range hint 1-7: LGTM!

The script setup is correctly specified.


43-45: LGTM!

The workspace member updates are correctly specified.


44-45: LGTM!

The cargo commands are correctly specified.

yash-prompt/src/expand_posix.rs (6)

1-15: LGTM!

The license header is correctly specified.


17-35: LGTM!

The documentation is complete and correctly specified.


19-24: LGTM!

The imports are correctly specified.


36-51: LGTM!

The function implementation is complete and correctly specified.


53-67: LGTM!

The helper function is complete and correctly specified.


69-167: LGTM!

The tests are complete and correctly specified.

yash-prompt/src/prompter.rs (3)

32-35: Caution: Avoid holding RefCell references across await points.

Holding a RefCell reference across await points can lead to runtime panics if the RefCell is borrowed again before the first borrow is released.

Ensure that all RefCell borrows are dropped before any await points to avoid potential runtime panics.


37-47: LGTM!

The new function correctly initializes the Prompter struct.


80-177: LGTM!

The test module provides comprehensive test coverage for the Prompter struct.

yash-prompt/LICENSE-GPL (1)

1-674: LGTM!

The LICENSE-GPL file contains the standard text for the GNU General Public License version 3.

yash-prompt/src/prompter.rs Show resolved Hide resolved
yash-prompt/src/prompter.rs Show resolved Hide resolved
yash-prompt/src/lib.rs Outdated Show resolved Hide resolved
@magicant magicant mentioned this pull request Jul 3, 2024
10 tasks
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bebdd66 and 9f20089.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (2)
  • yash-cli/Cargo.toml (1 hunks)
  • yash-cli/src/startup.rs (4 hunks)
Files skipped from review due to trivial changes (1)
  • yash-cli/Cargo.toml
Additional comments not posted (4)
yash-cli/src/startup.rs (4)

28-28: Import statement approved.

The use yash_env::option::State::On; import statement is necessary for using the On state in the code.


35-35: Import statement approved.

The use yash_prompt::Prompter; import statement is necessary for using the Prompter decorator in the code.


80-85: Documentation comments approved.

The added comments provide valuable information about the prepare_input function's behavior and the conditions under which the Prompter decorator is applied.


Line range hint 96-114: Conditional application of Prompter decorator approved.

The changes ensure that the Prompter decorator is applied when the shell is interactive and the source is the standard input. This is a correct and necessary modification.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9f20089 and b8472d5.

Files selected for processing (2)
  • yash-prompt/src/lib.rs (1 hunks)
  • yash-prompt/src/prompter.rs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • yash-prompt/src/lib.rs
  • yash-prompt/src/prompter.rs
Additional context used
Learnings (1)
Common learnings
Learnt from: magicant
PR: magicant/yash-rs#376
File: yash-prompt/src/lib.rs:17-19
Timestamp: 2024-07-03T03:32:18.685Z
Learning: The `yash-prompt` crate provides functionalities to show a command prompt, including the `expand_posix` function and the `Prompter` struct.

@magicant magicant merged commit a9248d1 into master Jul 3, 2024
6 checks passed
@magicant magicant deleted the prompt branch July 3, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant