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

Integrated Terminal: ctrl-c doesn't work in PowerShell and cmd.exe #9347

Closed
Chiliyago opened this issue Jul 15, 2016 · 39 comments · Fixed by #65569
Closed

Integrated Terminal: ctrl-c doesn't work in PowerShell and cmd.exe #9347

Chiliyago opened this issue Jul 15, 2016 · 39 comments · Fixed by #65569
Assignees
Labels
help wanted Issues identified as good community contribution opportunities terminal Integrated terminal issues upstream Issue identified as 'upstream' component related (exists outside of VS Code) windows VS Code on Windows issues
Milestone

Comments

@Chiliyago
Copy link

Chiliyago commented Jul 15, 2016

  • VSCode Version: 1.31
  • OS Version: Windows

Steps to Reproduce:
In version 1.3.1 I noticed that ctrl-c does not work and prevents exiting the current command. In my case I configured terminal to open PowerShell.

Example:

PS: >mkdir
cmdlet mkdir at command pipeline position 1
Supply values for the following parameters:
Path[0]:  <<ctrl-c should exit but it does not work>>
@weinand weinand added feature-request Request for new features or functionality terminal Integrated terminal issues and removed feature-request Request for new features or functionality labels Jul 15, 2016
@Tyriar
Copy link
Member

Tyriar commented Jul 15, 2016

@gerane @daviwil is this a recent regression?

@Tyriar Tyriar added info-needed Issue requires more information from poster windows VS Code on Windows issues labels Jul 15, 2016
@Tyriar Tyriar added this to the Backlog milestone Jul 15, 2016
@daviwil
Copy link
Contributor

daviwil commented Jul 16, 2016

I haven't tried it in previous builds so I'm not sure whether it ever worked.

@gerane
Copy link

gerane commented Jul 17, 2016

Yeah, it's never worked for me.

@Tyriar Tyriar added feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels Jul 17, 2016
@jmreicha
Copy link

jmreicha commented Jan 1, 2017

Any update on this?

@gerane
Copy link

gerane commented Jan 1, 2017

This might be caused by psreadline. I need to test it when I get a chance. I know I've noticed that it sometimes works and sometimes doesn't work. Also, sometimes if you click into a different part of the terminal and try it will work, but other times doing the same thing doesn't work. Ctrl+c doesn't work most often when a long running command is started. Shorter commands seem to have a better chance of worling if I recall. I often have to close the terminal out and open a new one because no matter what I try it won't stop.

I started work on documenting the impact of Psreadline on the terminal late last week here.

https://github.com/gerane/LineEndings

However, I got sick and am still not totally better so I haven't been able to work on it. I'm trying to help get as many of the issues documented with examples so we can start determining how we can improve the experience with powershell. Since windows 8 PSreadline is bundled with the OS and gets imported by default in ConesoleHost, so there are likely a lot of people who see these issues.

Another issue caused by Psreadline is ctrl+c for copy doesn't work in the prompt, only when highlighting in the output. At least I'm assuming it's caused by psreadline, haven't gotten to testing that yet.

I'll try to work on documenting the ctrl+c issues when I'm feeling better. I was starting to talk with @daviwil @Tyriar and a few others about it last week, but then I started to get sick.

@midnightfreddie
Copy link

I've recently started using the VSCode terminal for Powershell commands. (Windows v1.8.1.) I open the terminal, type Powershell then run commands.

I'm used to hitting control-C to clear the input line when I mistype a command or change my mind, but this does not clear the line in VSCode terminal as it does in the native console, so I have to backspace the entire line.

I mention this in case it's helpful/related to this issue, as it seems to me it might be.

@tylerjwatson
Copy link

I heeded some of the comments here alluding to it being PSReadline so I removed it, and can confirm it still happens even with PSReadline removed. The only difference being that PSReadline will echo the ^C glyph to the console, whereas the vanilla console will swallow it as a control character, but still not perform as intended.

@Tyriar Tyriar changed the title ctrl-c to exit not working in PowerShell Terminal Integrated Terminal: ctrl-c doesn't work in PowerShell and cmd.exe Apr 20, 2017
@Tyriar Tyriar added upstream Issue identified as 'upstream' component related (exists outside of VS Code) and removed feature-request Request for new features or functionality labels Apr 20, 2017
@Tyriar
Copy link
Member

Tyriar commented Apr 20, 2017

Upstream issue: microsoft/node-pty#7

@daveaglick
Copy link

I noticed this as well and have some data that may (or may not) be helpful. It looks like Ctrl-C is sent to C# applications as (ConsoleKey)3 from the VS Code terminal, which isn't even a valid value for the ConsoleKey enum. It's also not sent with the ConsoleModifiers.Control modifier as one would expect. However, even though it sends a odd value for Console.ReadKey(), it's still also interpreted as a cancel combination and will be handled by Console.CancelKeyPress. Even though this behavior is all being observed in a C# application, I suspect the terminal is sending similar odd data to any hosted process.

2017-06-30_09h54_39

@parkovski
Copy link

I fixed this on my own copy - the issue was src/agent/ConsoleInput.cc:398 which should not depend on the input mode:

    if (input[0] == '\x03') {
        // ...

and line 403, the early return in that block, should be deleted.

I'm not sure how this affects other uses of winpty, but it fixes Ctrl-C in the VSCode console for me. Here's a patched copy of winpty-agent.exe for anyone that needs this now (64-bit) - replace C:\Program Files\Microsoft VS Code\resources\app\node_modules\node-pty\build\Release\winpty-agent.exe with this and Ctrl-C should work in your integrated terminal.

@Gonkers
Copy link

Gonkers commented Sep 18, 2017

So what's the status on this? ctrl+c still doesn't work for me.

If I use c:\windows\System32\cmd.exe the keystroke just gets swallowed somewhere and has no effect.

If I use C:\WINDOWS\Sysnative\WindowsPowerShell\v1.0\powershell.exe as my shell, it just replicates ^C on my console output.

If I use C:\Windows\Sysnative\bash.exe as my shell ctrl-c works just fine.

Windows 10 pro fully patched as of today using v1.16.0 of VS Code.

Edit: powershell example
image

@vicatcu
Copy link

vicatcu commented Jan 23, 2018

I can confirm @parkovski commented on Sep 13, 2017 patched winpty-agent works with Win10 x64 and PowerShell terminal.

Version 1.19.2
Commit 490ef761b76b3f3b3832eff7a588aac891e5fe80
Date 2018-01-10T15:55:03.538Z
Shell 1.7.9
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

@entozoon
Copy link

The proffered solutions do not work for me, when opening a fresh terminal with ctrl-shift-c on Win10 x64 - ctrl-c often still being swallowed, which is odd because it's not powershell but doesn't seem to be the same terminal as typical cmd either.

@awsmhacks
Copy link

ctrl+break works for me. However, some keyboards wont have a break key and you will need to determine the mapping. On my dell laptop Break is mapped to ctrl+fn+b, which appears to act like ctrl+c did formally.

@oliverjanik
Copy link

oliverjanik commented Feb 14, 2018

This is a regression for me. I downloaded Jan 2018 update and this started happening again. There are many closed issues on this bug tracker for this strange problem already.

For me it's vscode -> Ctrl+Shift+C -> terminal opens -> run any process -> Ctrl-C does not kill the process.

It's somehow swallowed.

@Gonkers
Copy link

Gonkers commented Feb 15, 2018

VSCode terminal window is dead to me. I've seen the issues as well with no movement on them. So I gave up on it. In fact you reminded me to mute this thread. I have tried VSCode on a few brand new installs of windows and it's the same thing on each one. Maybe in a year or two it will work.

@parkovski
Copy link

For future reference, some Windows terminal issues (including this Ctrl-C one) are not easily fixed. There is currently an effort to design a PTY API for Windows, but until that ships, we have to rely on hacks because the functionality just isn’t there in Windows yet.

This is disappointing for me too. I don’t work for MS but I am participating in the API discussion because it’s something I’m passionate about seeing solved. Progress is being made, it’s just going to be a while.

For reference: microsoft/terminal#57

@BilibiliHentai
Copy link

BilibiliHentai commented Apr 2, 2018

By the way if you want to run python, you could press Ctrl-shift-p and "Python: Create Terminal", which let you create a terminal named "Python". Within this terminal Ctrl+c always works immediately.

This could be a temporary solution for ones working with python.

@thw0rted
Copy link

Just started seriously using VSCode on Windows after a year or so on Ubuntu. Looks like I'm stuck with Git Bash for my shell until they fix this?

@parkovski
Copy link

It's in progress. PTY support is enabled in skip ahead insider builds, it's just not exposed as a stable documented API yet so only usable through WSL interop, but it's working pretty well. You could actually have a better terminal at this point on skipahead builds by running the Linux VSCode in WSL and setting your shell to a Windows exe, which will go through a Linux PTY to an NT interop PTY.

str4d added a commit to str4d/zcash that referenced this issue Apr 18, 2018
Ctrl+C is not configured for Windows, as it does not work (yet):
microsoft/vscode#9347
microsoft/terminal#57
str4d added a commit to str4d/zcash that referenced this issue May 7, 2018
Ctrl+C is not configured for Windows, as it does not work (yet):
microsoft/vscode#9347
microsoft/terminal#57
str4d added a commit to str4d/zcash that referenced this issue May 24, 2018
Ctrl+C is not configured for Windows, as it does not work (yet):
microsoft/vscode#9347
microsoft/terminal#57
@gearskullguy
Copy link

I'm not sure how to fix this or any workarounds... I'm on Windows (7 Pro 64-bit), latest VS Code, and using Git Bash shell in the Terminal tab with User Settings "terminal.integrated.shell.windows": "C:\Program Files\Git\bin\bash.exe",

I also don't have a Break key on my laptop keyboard... and I'm right in the middle of a node session I need to restart. I can completely close the terminal but that's obnoxious.

@parkovski
Copy link

parkovski commented Jun 6, 2018

Find the node process, and type "kill -id <node pid>" in PowerShell, or if it's the only node running, "kill -name node". We technically have PTY support on insider builds now, but the API isn't official yet, so you'd have to make it open a WSL pty currently.

@saostad
Copy link

saostad commented Aug 10, 2018

I have same problem with git bash, but after press ctrl+c, if I wait like 5 minutes it will stop the "npm start" process for me.
I am using create-react-app typescript package
but if I use "docker-compose up" to run my docker container after I press ctrl+c it stop the container without problem.

After this problem I start using regular windows console and it works well, now my system works much faster! which is another problem with integrated terminal!

@saostad
Copy link

saostad commented Aug 13, 2018

I find what was my problem.
for some reason I had this in my settings:
"terminal.integrated.rendererType": "dom"
after I remove it it start working and it's much faster

str4d added a commit to str4d/zcash that referenced this issue Aug 17, 2018
Ctrl+C is not configured for Windows, as it does not work (yet):
microsoft/vscode#9347
microsoft/terminal#57
@simeyla
Copy link

simeyla commented Aug 23, 2018

How quaint.
I remember the first time I used Ctrl+C.
It was 22 years ago. I'm pretty sure it worked every time :-/

@Tyriar
Copy link
Member

Tyriar commented Aug 23, 2018

Update on this: I'm currently working on conpty support which is expected to fix this for newer versions of Windows 10 microsoft/node-pty#216

@oliverjanik
Copy link

Will this fix the external terminal as well?

@shinebayar-g
Copy link

2 years lol

@openm
Copy link

openm commented Dec 15, 2018

It seems like the intent of Ctrl+C as "copy" is to maintain consistent behavior across the Editor and the Terminal areas in VS Code on Windows. Keeping that in mind, are there alternative commands that can be used in the Terminal to send an interrupt (SIGINT) to the running process? Can anyone (maybe @Tyriar) explain how to create a new keyboard shortcut (Edit > Preferences > Keyboard Shortcuts) binding that sends a POSIX-style Ctrl+C to the Terminal while allowing the Windows Ctrl+C to remain "copy"?

@RReverser
Copy link

RReverser commented Dec 21, 2018

For anyone else experiencing this in Powershell, as a workaround you can add the following key handler to your $PROFILE:

Set-PSReadLineKeyHandler -Key (0x03 -as [char]) -Function CancelLine

This should fix the issue of not clearing a line on Ctrl+C while preserving default behaviour of copying text if it's already selected.

This won't help with the original issue though (Ctrl+C in other contexts), but at least should help with the most common annoyance.

@Tyriar
Copy link
Member

Tyriar commented Dec 21, 2018

ConPTY support is landing in the next Insiders build, this uses a new backend for the terminal on WIndows 10 build number 17692+, this is expected to fix many bugs in the terminal on Windows as we're adopting Microsoft's official pty API. For earlier versions winpty will still be used a many bugs will still remain (unless they're fixed in that project).

If you find any issues with conpty please report them to https://github.com/Microsoft/console (the team who own ConPTY) or this repo (if you think it's an integration issue). You can opt out of conpty by adding this setting:

"terminal.integrated.windowsEnableConpty": false

@microsoft microsoft locked as resolved and limited conversation to collaborators Dec 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Issues identified as good community contribution opportunities terminal Integrated terminal issues upstream Issue identified as 'upstream' component related (exists outside of VS Code) windows VS Code on Windows issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.