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

feat: configurable autoclose when shell exits #1699

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

weilirs
Copy link

@weilirs weilirs commented Jan 8, 2025

#1530

Configs in settings.json and widgets.json for terminals created by CMD + N and by clicking the "Terminal" button.

autoclose.mov

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Walkthrough

The pull request introduces new configuration options for terminal behavior across multiple files in the project. These changes enable more flexible terminal settings, specifically focusing on automatic closing mechanisms. The modifications span both frontend and backend components, adding new constants, type definitions, and configuration properties.

The key additions include settings for automatic terminal closure, such as enabling auto-close, configuring closure on error, and setting a delay for automatic closure. These settings are implemented consistently across the configuration files, type definitions, and frontend store, providing a comprehensive approach to enhancing terminal interaction and management.

The changes are implemented in a modular and extensible manner, allowing users to customize terminal behavior through global settings while maintaining the existing functionality of the application.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Copy link
Contributor

@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: 2

🧹 Nitpick comments (2)
frontend/app/store/keymodel.ts (1)

166-168: Consider using type-safe assertions and constant defaults.

The type assertions and default values could be improved for better maintainability and type safety.

Consider this approach:

-const termAutoClose = globalStore.get(getSettingsKeyAtom("term:autoclose")) as boolean | undefined;
-const termAutoCloseOnError = globalStore.get(getSettingsKeyAtom("term:autocloseonerror")) as boolean | undefined;
-const termAutoCloseDelay = globalStore.get(getSettingsKeyAtom("term:autoclosedelay")) as number | undefined;
+const DEFAULT_AUTO_CLOSE_DELAY = 2000;
+
+const termAutoClose = globalStore.get(getSettingsKeyAtom("term:autoclose")) as SettingsType["term:autoclose"];
+const termAutoCloseOnError = globalStore.get(getSettingsKeyAtom("term:autocloseonerror")) as SettingsType["term:autocloseonerror"];
+const termAutoCloseDelay = globalStore.get(getSettingsKeyAtom("term:autoclosedelay")) as SettingsType["term:autoclosedelay"];
pkg/wconfig/defaultconfig/widgets.json (1)

10-12: Consider adding comments to explain the relationship between settings.

The terminal widget configuration aligns with the new settings.json values, but the relationship between settings.json and these widget properties could be clearer:

  • cmd:closeonexit: maps to term:autoclose
  • cmd:closeonexitforce: maps to term:autocloseonerror
  • cmd:closeonexitdelay: maps to term:autoclosedelay

Consider adding JSON comments to document this mapping:

 "meta": {
     "view": "term",
     "controller": "shell",
+    // Controlled by term:autoclose in settings.json
     "cmd:closeonexit": true,
+    // Controlled by term:autocloseonerror in settings.json
     "cmd:closeonexitforce": false,
+    // Controlled by term:autoclosedelay in settings.json
     "cmd:closeonexitdelay": 2000
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c3eba2 and 6fcb5a0.

📒 Files selected for processing (6)
  • frontend/app/store/keymodel.ts (2 hunks)
  • frontend/types/gotypes.d.ts (1 hunks)
  • pkg/wconfig/defaultconfig/settings.json (1 hunks)
  • pkg/wconfig/defaultconfig/widgets.json (1 hunks)
  • pkg/wconfig/metaconsts.go (1 hunks)
  • pkg/wconfig/settingsconfig.go (1 hunks)
🔇 Additional comments (4)
pkg/wconfig/metaconsts.go (1)

38-40: LGTM! Well-organized constants.

The new terminal auto-close configuration constants are properly named and grouped with other terminal-related settings.

pkg/wconfig/settingsconfig.go (1)

65-67: LGTM! Well-structured settings fields.

The new settings fields are properly defined with:

  • Pointer types for optional values
  • Consistent naming
  • Proper JSON tags with omitempty
frontend/types/gotypes.d.ts (1)

604-606: LGTM! Consistent type definitions.

The TypeScript type definitions correctly mirror the Go struct fields and maintain type safety across the application.

pkg/wconfig/defaultconfig/widgets.json (1)

9-12: Verify the interaction between controller and cmd:close properties.*

Let's ensure the "shell" controller properly handles these new close-on-exit properties.

✅ Verification successful

Properties are properly implemented and documented

The shell controller correctly handles all close-on-exit properties:

  • cmd:closeonexit closes the block on successful exit (code 0)
  • cmd:closeonexitforce closes the block regardless of exit code
  • cmd:closeonexitdelay properly implements the configurable delay

The implementation in pkg/blockcontroller/blockcontroller.go is complete and matches the documented behavior in the customwidgets documentation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for shell controller implementation and its handling of close-on-exit properties
ast-grep --pattern 'class $_ implements Controller {
  $$$
  shell($$$) {
    $$$
  }
  $$$
}'

Length of output: 96


Script:

#!/bin/bash
# Find controller-related files
fd -t f controller

# Search for shell controller implementations or references
rg -i "shell.*controller" -A 5

# Search for close-on-exit property handling
rg -i "closeon(exit|Exit)" -A 3

Length of output: 12015

Comment on lines +174 to +175
"cmd:closeonexitforce": termAutoCloseOnError ?? false,
"cmd:closeonexitdelay": termAutoCloseDelay ?? 2000,
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Add the missing terminal auto-close setting

The cmd:closeonexit setting should be added as suggested. This is consistent with:

  • The default configuration in pkg/wconfig/defaultconfig/widgets.json
  • The documented behavior where this setting specifically handles auto-closing on successful exit
  • The pattern of using all three close-related settings together
🔗 Analysis chain

Use the extracted settings consistently.

The termAutoClose setting is retrieved but not used in the block definition.

Consider if this setting should affect the block definition:

 meta: {
     view: "term",
     controller: "shell",
     "cmd:closeonexitforce": termAutoCloseOnError ?? false,
     "cmd:closeonexitdelay": termAutoCloseDelay ?? 2000,
+    "cmd:closeonexit": termAutoClose ?? true,
 },
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Find termAutoClose definition and usage
rg "termAutoClose" -A 3 -B 3

# Search for terminal close-related settings
rg "cmd:closeonexit" -A 2 -B 2

# Search for similar block definitions
ast-grep --pattern 'meta: {
  view: "term",
  $$$
}'

Length of output: 6226

Comment on lines +24 to +27
"term:copyonselect": true,
"term:autoclose": true,
"term:autocloseonerror": false,
"term:autoclosedelay": 2000
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Terminal auto-close settings need documentation

While the auto-close feature is mentioned in the README, the specific configuration options (term:autoclose, term:autocloseonerror, term:autoclosedelay) are not documented. Consider:

  • Adding these settings to the user documentation
  • Including descriptions of their purpose and effects
  • Documenting the default values and their rationale
🔗 Analysis chain

LGTM! Terminal autoclose settings are well-structured.

The new terminal settings follow consistent naming conventions and provide sensible defaults:

  • term:autoclose: true (enables the feature by default)
  • term:autocloseonerror: false (prevents unexpected closures on errors)
  • term:autoclosedelay: 2000 (provides reasonable 2-second delay)

Let's verify these settings are properly documented:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if these settings are documented in README or docs
rg -i "term:autoclose|term:autocloseonerror|term:autoclosedelay" docs/ README.md || echo "Settings documentation not found"

Length of output: 157


Script:

#!/bin/bash
# Search for any markdown files containing terminal-related documentation
fd -e md | xargs rg -i "terminal|term" -A 2 -B 2

# Look for schema files and check terminal settings
fd "schema|config" -e json | xargs rg -i "term:autoclose|term:autocloseonerror|term:autoclosedelay" -A 2 -B 2

# Check for comments near the settings definition
rg -C 5 "term:autoclose" pkg/wconfig/defaultconfig/settings.json

Length of output: 13695

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant