diff --git a/README.md b/README.md index 410d8f03e8d..5a5301b3b52 100644 --- a/README.md +++ b/README.md @@ -868,6 +868,34 @@ SQLite (https://www.sqlite.org) is in the Public Domain. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +### terminal/shellintegrations/clink + + The Terminal plugin uses a lua script to integrate with the cmd shell when using clink. + + https://github.com/chrisant996/clink-gizmos + + MIT License + + Copyright (c) 2023 Chris Antos + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + ### cmake The CMake project manager uses the CMake lexer code for parsing CMake files diff --git a/doc/qtcreator/src/overview/creator-acknowledgements.qdoc b/doc/qtcreator/src/overview/creator-acknowledgements.qdoc index 7f193d124dc..7f607374759 100644 --- a/doc/qtcreator/src/overview/creator-acknowledgements.qdoc +++ b/doc/qtcreator/src/overview/creator-acknowledgements.qdoc @@ -1059,6 +1059,18 @@ \include license-mit.qdocinc + \li \b terminal/shellintegrations/clink + + The Terminal plugin uses a lua script to integrate with the cmd shell when using clink. + + \list + \li \l https://github.com/chrisant996/clink-gizmos + \endlist + + Distributed under the MIT license. + + \include license-mit.qdocinc + \li \b cmake The CMake project manager uses the CMake lexer code for parsing CMake files. diff --git a/src/plugins/terminal/shellintegration.cpp b/src/plugins/terminal/shellintegration.cpp index fd4c1364696..00f1b75cd69 100644 --- a/src/plugins/terminal/shellintegration.cpp +++ b/src/plugins/terminal/shellintegration.cpp @@ -41,6 +41,10 @@ struct { FilePath script{":/terminal/shellintegrations/shellintegration.ps1"}; } pwsh; + struct + { + FilePath script{":/terminal/shellintegrations/shellintegration-clink.lua"}; + } clink; } filesToCopy; // clang-format on @@ -64,6 +68,9 @@ bool ShellIntegration::canIntegrate(const Utils::CommandLine &cmdLine) return true; } + if (cmdLine.executable().baseName() == "cmd") + return true; + return false; } @@ -105,6 +112,7 @@ void ShellIntegration::prepareProcess(Utils::QtcProcess &process) return; env.set("VSCODE_INJECTION", "1"); + env.set("TERM_PROGRAM", "vscode"); if (cmd.executable().baseName() == "bash") { const FilePath rcPath = filesToCopy.bash.rcFile; @@ -134,6 +142,14 @@ void ShellIntegration::prepareProcess(Utils::QtcProcess &process) cmd.addArgs(QString("-noexit -command try { . \"%1\" } catch {}{1}").arg(tmpRc.nativePath()), CommandLine::Raw); + } else if (cmd.executable().baseName() == "cmd") { + const FilePath rcPath = filesToCopy.clink.script; + const FilePath tmpRc = FilePath::fromUserInput( + m_tempDir.filePath(filesToCopy.clink.script.fileName())); + rcPath.copyFile(tmpRc); + + env.set("CLINK_HISTORY_LABEL", "QtCreator"); + env.appendOrSet("CLINK_PATH", tmpRc.parentDir().nativePath(), ";"); } process.setCommand(cmd); diff --git a/src/plugins/terminal/shellintegrations/shellintegration-clink.lua b/src/plugins/terminal/shellintegrations/shellintegration-clink.lua new file mode 100644 index 00000000000..ff9d5f3facc --- /dev/null +++ b/src/plugins/terminal/shellintegrations/shellintegration-clink.lua @@ -0,0 +1,52 @@ +-- Copyright (c) 2023 Chris Antos +-- SPDX-License-Identifier: MIT + +-- luacheck: globals vscode_shell_integration NONL +if vscode_shell_integration == nil then + vscode_shell_integration = true +end + +if not vscode_shell_integration then + return +end + +local function is_vscode() + local term_program = os.getenv("term_program") or "" + if term_program:lower() == "vscode" then + return true + end +end + +local function send_context() + if is_vscode() then + local codes = "" + codes = codes .. "\027]633;D;" .. os.geterrorlevel() .. "\a" -- send command exit code + codes = codes .. "\027]633;P;Cwd=" .. os.getcwd() .. "\a" -- send cwd as title + clink.print(codes, NONL) + end +end + +local p = clink.promptfilter(-999) + +function p:filter() -- luacheck: no unused + -- Nothing to do here, but the filter function must be defined. +end + +function p:surround() -- luacheck: no unused + if is_vscode() then + local pre, suf + local rpre, rsuf + + -- ESC codes surrounding prompt string + pre = "\027]633;A\a" -- copied from shellIntegration-rc.zsh + suf = "\027]633;B\a" -- copied from shellIntegration-rc.zsh + + -- ESC codes surrounding right side prompt string + rpre = "\027]633;H\a" -- copied from shellIntegration-rc.zsh + rsuf = "\027]633;I\a" -- copied from shellIntegration-rc.zsh + + return pre, suf, rpre, rsuf + end +end + +clink.onbeginedit(send_context) diff --git a/src/plugins/terminal/terminal.qrc b/src/plugins/terminal/terminal.qrc index 50fcff4f2f0..63c28169dfd 100644 --- a/src/plugins/terminal/terminal.qrc +++ b/src/plugins/terminal/terminal.qrc @@ -1,15 +1,16 @@ - - images/settingscategory_terminal.png - images/settingscategory_terminal@2x.png - images/terminal.png - images/terminal@2x.png - shellintegrations/shellintegration-bash.sh - shellintegrations/shellintegration-env.zsh - shellintegrations/shellintegration-login.zsh - shellintegrations/shellintegration-profile.zsh - shellintegrations/shellintegration-rc.zsh - shellintegrations/shellintegration.fish - shellintegrations/shellintegration.ps1 - + + images/settingscategory_terminal.png + images/settingscategory_terminal@2x.png + images/terminal.png + images/terminal@2x.png + shellintegrations/shellintegration-bash.sh + shellintegrations/shellintegration-env.zsh + shellintegrations/shellintegration-login.zsh + shellintegrations/shellintegration-profile.zsh + shellintegrations/shellintegration-rc.zsh + shellintegrations/shellintegration.fish + shellintegrations/shellintegration.ps1 + shellintegrations/shellintegration-clink.lua +