Title: Preexec hook for REPL · Issue #122622 · python/cpython · GitHub
Open Graph Title: Preexec hook for REPL · Issue #122622 · python/cpython
X Title: Preexec hook for REPL · Issue #122622 · python/cpython
Description: Feature or enhancement Proposal: Background In VS Code we override PS1 to enable shell integration, this currently gives VS Code understanding of where the commands are and what they are. This provides a few features: Command decorations...
Open Graph Description: Feature or enhancement Proposal: Background In VS Code we override PS1 to enable shell integration, this currently gives VS Code understanding of where the commands are and what they are. This prov...
X Description: Feature or enhancement Proposal: Background In VS Code we override PS1 to enable shell integration, this currently gives VS Code understanding of where the commands are and what they are. This prov...
Opengraph URL: https://github.com/python/cpython/issues/122622
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Preexec hook for REPL","articleBody":"# Feature or enhancement\n\n### Proposal:\n\n## Background\n\nIn VS Code we override PS1 to enable shell integration, this currently gives VS Code understanding of where the commands are and what they are. This provides a few features:\n\nCommand decorations with visualization of exit/error status:\n\n\n\nCommand navigation (cmd/ctrl+up/down):\n\n\n\nRun recent (ctrl+alt+r):\n\n\n\nTo give an example of what's possible with shell integration, here's our experimental VS Code-native PowerShell intellisense:\n\n\n\nAnd multi-line sticky scroll:\n\n\n\n## Request\n\nSomething we needed to work around for Python was the lack of a pre-execution hook, we would normally print `\\x1b[633;C\\a` at the end of a command just before it's run such that VS Code knows where that marker is. Currently we have to stick that at the start of the command input though which can degrade the experience, especially when VS Code attempts to figure out that command has been run manually.\n\nTo visualization of the problem, see the A, B, C, D markers in our python REPL:\n\n\n\nCompare this to PowerShell which positions them correctly:\n\n\n\nShell integration script included in VS Code's python extension: https://github.com/microsoft/vscode-python/blob/main/python_files/pythonrc.py\n\nI'm not a Python dev so I'm not sure what such an API would look like, but we essentially need a hook to run arbitrary code immediately before the REPL runs the command, something like this:\n\n```py\nclass MyPreexec:\n def __str__(self):\n return \"preexec\"\n\nsys.preexec = MyPreexec()\n```\n\ncc @anthonykim1 @brettcannon \n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-144724\n* gh-157241\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/Tyriar","@type":"Person","name":"Tyriar"},"datePublished":"2024-08-02T15:46:34Z","url":"https://github.com/python/cpython/issues/122622"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:87b160cf-077a-34a7-0051-cc221af1b2c4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 91A4:B4351:BED1AB:1116ACB:6AFDA7B0 |
| html-safe-nonce | 47621f4280be6f5c811e25973e8f4c4dd5555049c92d1e48912e8139193e91ce |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUE0OkI0MzUxOkJFRDFBQjoxMTE2QUNCOjZBRkRBN0IwIiwidmlzaXRvcl9pZCI6IjE1MDA5MzE1MzA4OTE4MzEyMTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a675f2e7ff6284d01a669f87295e411a673c57494a6cdd804a93639dbce3addc |
| hovercard-subject-tag | issue:2445266510 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/122622/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8b08c5be9699c49a8ecd12b4797614ebaccc56af53089eae99df97ae7ce793fa/python/cpython/issues/122622 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8b08c5be9699c49a8ecd12b4797614ebaccc56af53089eae99df97ae7ce793fa/python/cpython/issues/122622 |
| og:image:alt | Feature or enhancement Proposal: Background In VS Code we override PS1 to enable shell integration, this currently gives VS Code understanding of where the commands are and what they are. This prov... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Tyriar |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width