1

I have the following piece of code in my task.json:

    {
        "taskName": "Run",
        "suppressTaskName": true,
        "args": [
            "${workspaceRoot}/bin/Albedo"
        ]
    }

When I run "Run" the program starts as it is supposed to, but when I have getchar() in the code nothing happens when I the program it get stuck in the output. There is no place where I can press Enter to continue.

So I am thinking about how do I open the integrated terminal and run it from there? Would it be possible to call such a command from task.json?

El_Loco
  • 1,716
  • 4
  • 20
  • 35

2 Answers2

1

This feature was actually added in the upcoming January release, see this section of the release notes draft. Essentially, you just have to add this to your tasks.json:

"_runner": "terminal"

If you don't want to wait until release (which should be soon) to check this out, you can use an Insider's build.

Gama11
  • 31,714
  • 9
  • 78
  • 100
  • Do you know if it will possible to map keyboard short-cuts to different tasks as well? – El_Loco Jan 31 '17 at 10:49
  • See http://stackoverflow.com/questions/30057191/is-it-possible-to-assign-different-shortcuts-to-different-tasks-in-vs-code – Gama11 Jan 31 '17 at 10:58
1

To interactively run code in the integrated terminal, either a single line at a time or multiple selected lines by simply pressing ctrl+enter, I did the following:

  1. Install macros extension.

  2. Add the following to User Settings

"macros": {
    "canCopyEmpty": [
        "expandLineSelection",
        "editor.action.clipboardCopyAction",
        "cancelSelection"
    ],
    "runLine": [
        "macros.canCopyEmpty",
        "workbench.action.terminal.paste",
        {
            "command": "workbench.action.focusActiveEditorGroup",
            "when": "terminalFocus"
        }
    ],
    "runSelection": [
        "workbench.action.terminal.runSelectedText",
        "cursorDown"
    ]
}
  1. Add the following to keybindings.json
{
    "key": "ctrl+enter",
    "command": "macros.runLine",
    "args": {
        "cmd": "ls",
        "match": ".*"
    },
    "when": "editorTextFocus && !editorHasSelection"
},
{
    "key": "ctrl+enter",
    "command": "macros.runSelection",
    "args": {
        "cmd": "ls",
        "match": ".*"
    },
    "when": "editorTextFocus && editorHasSelection"
}
Clay
  • 2,584
  • 1
  • 28
  • 63
  • 1
    This is an old answer, and changes to the VSCode core broke the keybindings in the original answer. I have updated it with `keybindings` and `user settings` that work with the most recent release of VSCode. Nothing to prevent future changes from breaking it again. – Clay Aug 28 '19 at 12:49