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

Show $PS2 prompt for continuation lines in the read built-in #380

Merged
merged 5 commits into from
Jul 6, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Jul 6, 2024

Summary by CodeRabbit

  • New Features

    • read built-in now displays a prompt for continued lines in interactive mode.
    • Added method to check if the environment is interactive.
  • Improvements

    • Enhanced prompt functionality for better user interaction.
  • Documentation

    • Updated changelogs to reflect new features and improvements.

This commit extracts the `fetch_posix` function from the `print_prompt`
function in `yash-prompt`. The extracted function is now public and
helps to fetch the prompt string from the variable set.
@magicant magicant added this to the 0.1.0 β2 milestone Jul 6, 2024
@magicant magicant self-assigned this Jul 6, 2024
Copy link

coderabbitai bot commented Jul 6, 2024

Walkthrough

This update introduces enhancements across various modules for the Yash shell. Key changes include adding dependency checks for complex builds, updating built-in functionalities, refining environment detection for interactivity, and improving prompt handling. These modifications aim to align the project with POSIX 2018 requirements, optimize the code, and enhance user interaction.

Changes

Files/Paths Change Summaries
check-extra.sh Added extra cargo check and cargo build commands focusing on yash-builtin and yash-syntax dependency checks and builds with different features.
yash-builtin/CHANGELOG.md Updated for read built-in prompt, break, and continue semantics.
yash-builtin/Cargo.toml Added yash-prompt to default features, made it an optional dependency.
.../src/read.rs Documented prompt requirement for yash-prompt feature.
.../src/read/input.rs Updated read function for interactive prompts, added print_prompt.
yash-cli/CHANGELOG.md Documented read built-in prompt addition in CLI.
yash-env/CHANGELOG.md Added Env::is_interactive method.
yash-env/src/lib.rs Introduced Interactive option and is_interactive method in Env.
yash-prompt/src/lib.rs Added fetch_posix function in prompter module.
.../src/prompter.rs Refactored print_prompt, added fetch_posix, reorganized logic for prompt fetching and expansion.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant YashCLI
    participant YashBuiltin
    participant YashEnv
    participant YashPrompt

    User->>YashCLI: Enter command with read built-in
    YashCLI->>YashEnv: Check if interactive (is_interactive)
    YashEnv-->>YashCLI: Return interactivity status
    YashCLI->>YashBuiltin: Call read function
    YashBuiltin->>YashPrompt: Fetch and print prompt for continuation (fetch_posix)
    YashPrompt-->>YashBuiltin: Return prompt string
    YashBuiltin-->>User: Display prompt and read input
Loading

Possibly related issues

  • magicant/yash-rs#336: These changes address interactivity and prompt improvements which are part of the necessary updates for the first beta release of Yash.

Poem

In the land of code so fine,
Yash's features now align.
Prompts that glow, interactivity flows,
Enhanced with care, for users to share.
A build so strong, to last for long,
With each command, the shell's true song.


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.

@magicant magicant mentioned this pull request Jul 6, 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: 1

Outside diff range and nitpick comments (1)
yash-env/CHANGELOG.md (1)

15-15: Fix unordered list indentation.

The unordered list indentation should be 2 spaces instead of 4 to adhere to the Markdownlint rule MD007.

-    - This is a decorator of `Input` that implements the behavior of the verbose shell option.
+  - This is a decorator of `Input` that implements the behavior of the verbose shell option.
Tools
Markdownlint

15-15: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3deeda0 and 6677824.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (10)
  • check-extra.sh (1 hunks)
  • yash-builtin/CHANGELOG.md (1 hunks)
  • yash-builtin/Cargo.toml (2 hunks)
  • yash-builtin/src/read.rs (1 hunks)
  • yash-builtin/src/read/input.rs (4 hunks)
  • yash-cli/CHANGELOG.md (1 hunks)
  • yash-env/CHANGELOG.md (1 hunks)
  • yash-env/src/lib.rs (2 hunks)
  • yash-prompt/src/lib.rs (2 hunks)
  • yash-prompt/src/prompter.rs (4 hunks)
Files skipped from review due to trivial changes (2)
  • yash-builtin/Cargo.toml
  • yash-builtin/src/read.rs
Additional context used
Learnings (3)
yash-prompt/src/lib.rs (1)
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.
yash-prompt/src/prompter.rs (1)
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.
yash-builtin/src/read/input.rs (1)
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.
Markdownlint
yash-env/CHANGELOG.md

15-15: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

Additional comments not posted (14)
yash-cli/CHANGELOG.md (1)

37-37: Changelog entry is clear and concise.

The description of the new feature for the read built-in is well-documented.

check-extra.sh (4)

21-21: Addition of cargo check command for yash-builtin package is appropriate.

The new command ensures that unnecessary dependencies are checked for the yash-builtin package without default features.


22-22: Addition of cargo check command for yash-builtin package with yash-semantics feature is appropriate.

The new command ensures that unnecessary dependencies are checked for the yash-builtin package with the yash-semantics feature.


23-23: Addition of cargo check command for yash-syntax package is appropriate.

The new command ensures that unnecessary dependencies are checked for the yash-syntax package without default features.


29-29: Addition of cargo build command for yash-builtin package with yash-semantics feature is appropriate.

The new command ensures that the yash-builtin package can be built with the yash-semantics feature and no default features.

yash-builtin/CHANGELOG.md (1)

17-17: Changelog entry is clear and concise.

The description of the new feature for the read built-in is well-documented.

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

30-31: Documentation of fetch_posix function is clear and concise.

The description of the new function for fetching the value of a variable defined by POSIX for a prompt string is well-documented.


75-75: Export of fetch_posix function is appropriate.

The new function is now publicly accessible from the prompter module.

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

22-22: Good use of constants for variable names.

Using constants like PS1 and PS2 for variable names improves maintainability and reduces the risk of errors.


63-70: Ensure prompt expansion handles edge cases.

The print_prompt function correctly fetches and expands the prompt string. Ensure that the expand_posix function handles all edge cases, such as special characters and nested expansions.

yash-builtin/src/read/input.rs (3)

98-99: Update documentation to mention the yash-prompt feature.

The documentation correctly mentions the requirement of the yash-prompt feature for interactive prompts.


118-118: Ensure print_prompt function is called correctly.

The print_prompt function is called when a line continuation is encountered. Ensure that it is called in all necessary scenarios.


183-211: Good implementation of the print_prompt function.

The print_prompt function is well-implemented, checking for an interactive shell and terminal input before printing the prompt.

yash-env/src/lib.rs (1)

306-315: Correct implementation of is_interactive method.

The is_interactive method correctly checks the Interactive option and the stack for Frame::Subshell.

yash-prompt/src/prompter.rs Outdated Show resolved Hide resolved
My plan for yash-specific prompt variable support is to add a new
function `fetch_ex` that will handle the `$YASH_PS1` and `$YASH_PS2`
variables. To make this clear, this commit moves the TODO comment
out of the `fetch_posix` function.
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 6677824 and d680905.

Files selected for processing (1)
  • yash-prompt/src/prompter.rs (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • yash-prompt/src/prompter.rs

@magicant magicant merged commit 6fa7626 into master Jul 6, 2024
6 checks passed
@magicant magicant deleted the read-builtin-prompt branch July 6, 2024 14:15
@magicant magicant mentioned this pull request Jul 21, 2024
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant