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

Implement ignore-eof shell option #413

Merged
merged 5 commits into from
Sep 4, 2024
Merged

Implement ignore-eof shell option #413

merged 5 commits into from
Sep 4, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Sep 1, 2024

Closes #408

  • Support terminal file type in the virtual system
  • IgnoreEof decorator
    • Don't ignore EOF if the input is not a terminal
  • Use the decorator

Summary by CodeRabbit

  • New Features

    • Enhanced interactive shell functionality with job status updates before prompts.
    • Introduced ignoreeof option to prevent accidental shell exits on EOF.
    • Added support for terminal file types in file handling.
    • Improved input preparation process with clearer decorator application logic.
  • Bug Fixes

    • Improved robustness by preventing shell exits on syntax errors.
  • Documentation

    • Updated documentation for clarity on ignore-eof option and related functionalities.

Copy link

coderabbitai bot commented Sep 1, 2024

Walkthrough

The changes introduce enhancements to the interactive shell functionality, including the implementation of the ignore-eof option, which allows the shell to ignore EOF signals when reading input from terminals. This feature is supported by a new IgnoreEof decorator and modifications to input handling processes. Additionally, improvements to job status reporting and error handling in interactive shells are included, contributing to a more robust user experience.

Changes

Files Change Summary
yash-cli/CHANGELOG-bin.md Added details about enhancements to interactive shells, including job status reporting and error handling.
yash-cli/CHANGELOG-lib.md Updated startup::input::prepare_input function with new lifetime parameters and decorator logic.
yash-cli/src/startup/input.rs Restructured prepare_input function to apply decorators based on interactivity; added prepare_fd_input function.
yash-env/CHANGELOG.md Documented new entities like job::fmt::Accumulator, input::Reporter, and input::IgnoreEof.
yash-env/src/input.rs Introduced ignore_eof module and exported IgnoreEof.
yash-env/src/input/ignore_eof.rs Implemented IgnoreEof decorator to handle EOF signals in interactive shells.
yash-env/src/system/virtual.rs Modified isatty function to accurately check if a file descriptor is a terminal.
yash-env/src/system/virtual/file_system.rs Added Terminal variant to FileBody enum for terminal device representation.
yash-env/src/system/virtual/io.rs Changed field visibility in OpenFileDescription and expanded methods to include terminal handling.
yash-semantics/src/runner.rs Updated documentation for read_eval_loop and interactive_read_eval_loop functions.

Assessment against linked issues

Objective Addressed Explanation
Activate the ignore-eof option (408)
Ensure the ignore-eof option only affects terminal input (408)
Implement a configurable warning message for EOF (408)
Clarify documentation regarding the ignore-eof option (408)

Poem

In the meadow, I hop with glee,
The shell's new tricks delight me!
Ignore EOF, oh what a treat,
With every line, my joy's complete!
A prompt that shines, a job well done,
Let's play and code, oh what fun! 🐇✨


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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 self-assigned this Sep 1, 2024
@magicant magicant added the enhancement New feature or request label Sep 1, 2024
@magicant magicant added this to the 0.1.0 β3 milestone Sep 1, 2024
The fields of OpenFileDescription are now pub(crate) instead of
pub(super). This is because the fields are used in the tests of
IgnoreEof, which is in a different module.
@magicant magicant marked this pull request as ready for review September 3, 2024 16:21
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

Outside diff range, codebase verification and nitpick comments (1)
yash-cli/CHANGELOG-bin.md (1)

28-28: Consider rewording the sentences to avoid repetition.

The static analysis tool has correctly flagged that three successive sentences begin with "Interactive shells". To improve readability, consider rewording the sentences or using synonyms to avoid the repetition.

Here's a suggestion:

-Interactive shells now ignore the `noexec` option.
-Interactive shells now support the `ignoreeof` option.
-Interactive shells now allow modifying the trap for signals that were ignored
+The `noexec` option is now ignored by interactive shells.
+Support for the `ignoreeof` option has been added to interactive shells.
+Modifying the trap for signals that were ignored
 on the shell startup.
Tools
LanguageTool

[style] ~28-~28: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...hells now ignore the noexec option. - Interactive shells now support the ignoreeof opti...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 77ba94d and 6133778.

Files selected for processing (10)
  • yash-cli/CHANGELOG-bin.md (1 hunks)
  • yash-cli/CHANGELOG-lib.md (1 hunks)
  • yash-cli/src/startup/input.rs (4 hunks)
  • yash-env/CHANGELOG.md (2 hunks)
  • yash-env/src/input.rs (1 hunks)
  • yash-env/src/input/ignore_eof.rs (1 hunks)
  • yash-env/src/system/virtual.rs (1 hunks)
  • yash-env/src/system/virtual/file_system.rs (4 hunks)
  • yash-env/src/system/virtual/io.rs (6 hunks)
  • yash-semantics/src/runner.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • yash-semantics/src/runner.rs
Additional context used
Learnings (1)
yash-env/src/system/virtual.rs (1)
Learnt from: magicant
PR: magicant/yash-rs#405
File: yash-cli/src/startup/input.rs:88-88
Timestamp: 2024-08-22T13:22:00.012Z
Learning: The `isatty` function in the `yash-env` project now returns a `bool` instead of a `Result<bool>`.
LanguageTool
yash-cli/CHANGELOG-bin.md

[style] ~28-~28: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...hells now ignore the noexec option. - Interactive shells now support the ignoreeof opti...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

yash-env/CHANGELOG.md

[style] ~17-~17: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...to the user. - input::IgnoreEof - This Input decorator implements the behavi...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~19-~19: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...tem::virtual::FileBody::Terminal - This is a new variant ofFileBody` that rep...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

Additional comments not posted (27)
yash-env/src/input.rs (1)

32-33: LGTM!

The introduction of the ignore_eof module and the export of the IgnoreEof entity align with the PR objectives and the goals outlined in the linked issue #408. The placement of the module in the yash-env crate and the export of the IgnoreEof entity as a public API are consistent with the suggestions and requirements discussed in the issue.

The code changes are approved.

yash-cli/CHANGELOG-bin.md (1)

28-28: LGTM!

The changelog entry accurately reflects the new ignoreeof option feature for interactive shells, as described in the PR summary and linked issue.

Tools
LanguageTool

[style] ~28-~28: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...hells now ignore the noexec option. - Interactive shells now support the ignoreeof opti...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

yash-cli/CHANGELOG-lib.md (1)

34-43: Enhancements to prepare_input function for interactive shell environments.

The changes to the startup::input::prepare_input function significantly improve the user experience in interactive shell environments:

  • The yash_env::input::Reporter decorator reports the job status.
  • The yash_env::input::IgnoreEof decorator ignores the EOF character for input from file descriptors, allowing the shell to continue processing after EOF. This aligns with the PR objective of implementing the ignore-eof option.
  • The yash_prompt::Prompter decorator displays the prompt before reading input, and its application has been expanded from only standard input to include input from any file descriptor.

These enhancements collectively contribute to a more user-friendly interactive shell experience.

yash-cli/src/startup/input.rs (7)

32-32: LGTM!

The code changes are approved.


36-36: LGTM!

The code changes are approved.


69-82: LGTM!

The code changes are approved.


Line range hint 95-104: LGTM!

The code changes are approved.


126-126: LGTM!

The code changes are approved.


133-140: LGTM!

The code changes are approved.


146-170: LGTM!

The code changes are approved.

yash-env/CHANGELOG.md (2)

12-19: LGTM!

The additions are well-documented and provide a clear overview of the new functionality. The descriptions are concise and informative.

Tools
LanguageTool

[style] ~17-~17: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...to the user. - input::IgnoreEof - This Input decorator implements the behavi...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~19-~19: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...tem::virtual::FileBody::Terminal - This is a new variant ofFileBody` that rep...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


23-25: LGTM!

The changes are well-documented and provide a clear overview of the modifications. The descriptions are concise and informative.

yash-env/src/input/ignore_eof.rs (6)

27-45: Excellent module documentation!

The module documentation provides a clear and comprehensive overview of the IgnoreEof decorator. It covers the purpose, conditions for effectiveness, and the behavior in handling EOF scenarios. Well done!


46-55: Well-structured IgnoreEof struct definition!

The IgnoreEof struct is well-defined with appropriate fields and generic lifetime parameters. The use of RefCell for the environment is suitable for shared mutable access. Good job!


57-80: Well-implemented new function!

The new function is a well-designed constructor for the IgnoreEof struct. It takes the necessary arguments and initializes the struct fields appropriately. The documentation comment provides clear explanations of each argument, making it easy to understand and use the constructor correctly. Great work!


82-109: Correctly implemented next_line function!

The next_line function properly implements the behavior of the IgnoreEof decorator. It handles EOF scenarios by checking the relevant conditions and re-reading the input if necessary. The use of a loop with a maximum number of tries prevents infinite looping. The function also correctly accesses the environment using RefCell and borrow(). Well done!


111-379: Comprehensive test module!

The test module provides thorough test coverage for the IgnoreEof decorator. It covers various scenarios, including reading from the inner input, handling EOF, and considering different shell options and terminal status. The use of VirtualSystem enables controlled testing environments. The tests effectively verify the expected behavior and error messages, ensuring the correctness of the decorator's implementation. Excellent work on the tests!


1-379: Review completed successfully!

The ignore_eof.rs file has been thoroughly reviewed, and all code segments have been approved. The implementation of the IgnoreEof decorator is well-structured, properly documented, and comprehensively tested. No further changes or improvements are necessary. Great job on this implementation!

yash-env/src/system/virtual/file_system.rs (2)

Line range hint 215-254: LGTM!

The addition of the Terminal variant to the FileBody enum is a valid change to represent a terminal device in the file system. The content field allows storing virtual file content for the terminal device, and the comment provides clarity on its purpose and behavior.


285-285: LGTM!

The type and size methods of the FileBody enum are correctly updated to handle the new Terminal variant. The type method maps it to the CharacterDevice file type, and the size method returns 0, which is consistent with the comment indicating that it is a dummy device.

Also applies to: 297-297

yash-env/src/system/virtual/io.rs (6)

41-56: LGTM!

The changes to the OpenFileDescription struct are approved:

  • Changing the visibility of the fields to pub(crate) enhances their accessibility within the crate, potentially facilitating easier integration and manipulation of file descriptions.
  • The documentation comment changes contribute to a more uniform style.

93-95: LGTM!

The change to include FileBody::Terminal in the match arm of the is_ready_for_reading method is approved. This change indicates that terminal file types are now treated similarly to regular files and directories regarding readiness for reading operations, which may improve the overall behavior of file operations in the system.


108-110: LGTM!

The change to include FileBody::Terminal in the match arm of the is_ready_for_writing method is approved. This change indicates that terminal file types are now treated similarly to regular files and directories regarding readiness for writing operations, which may improve the overall behavior of file operations in the system.


126-126: LGTM!

The change to include FileBody::Terminal in the match arm of the read method is approved. This change allows the read method to handle terminal file types similarly to regular files, which may improve the overall behavior of file operations in the system.


172-172: LGTM!

The change to include FileBody::Terminal in the match arm of the write method is approved. This change allows the write method to handle terminal file types similarly to regular files, which may improve the overall behavior of file operations in the system.


220-220: LGTM!

The change to return an error for FileBody::Terminal in the match arm of the seek method is approved. This change prevents seeking operations on terminal file types, which is consistent with the behavior for symlinks and may improve the overall behavior of file operations in the system.

yash-env/src/system/virtual.rs (1)

540-544: LGTM!

The changes to the isatty function look good. It now correctly checks if the file descriptor is associated with a terminal using with_open_file_description.

This makes sure the next prompt starts at the beginning of the line.
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 6133778 and b555ea4.

Files selected for processing (1)
  • yash-cli/src/startup/input.rs (4 hunks)
Additional comments not posted (5)
yash-cli/src/startup/input.rs (5)

69-82: LGTM!

The updated documentation comments accurately reflect the changes in the prepare_input function and provide clear guidance on how the decorators are applied based on the source and the interactive option.


Line range hint 95-104: LGTM!

The changes improve the handling of the standard input source by setting it to non-blocking mode when required and using the new prepare_fd_input function to create the input object with the appropriate decorators.


126-126: LGTM!

The change is consistent with the changes made for the Stdin case and improves the code by using the new prepare_fd_input function to create the input object with the appropriate decorators.


133-140: LGTM!

The changes improve the handling of the command string source by creating a Memory input object and applying the Reporter decorator if the interactive option is enabled. This is consistent with the behavior for other input sources.


147-170: LGTM!

The new prepare_fd_input function encapsulates the logic for creating an input object from a file descriptor and applying the appropriate decorators based on the interactive option. This improves the code by centralizing the decorator logic and making it reusable for different input sources.

@magicant magicant merged commit 36469de into master Sep 4, 2024
7 checks passed
@magicant magicant deleted the ignore-eof branch September 4, 2024 16:13
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.

Activate the ignore-eof option
1 participant