ソースを参照

feat(clipboard): Allow copy from command.

Specify one command that is run and the output is copy to clipboard.
Marcelo Fornet 5 年 前
コミット
025d5943f1
3 ファイル変更26 行追加3 行削除
  1. 7 1
      package.json
  2. 1 1
      src/core.ts
  3. 18 1
      src/extension.ts

+ 7 - 1
package.json

@@ -48,6 +48,12 @@
                         "description": "Path to python executable.",
                         "scope": "resource"
                     },
+                    "acmx.configuration.copyToClipboardCommand": {
+                        "type": "string",
+                        "default": "",
+                        "description": "Command to run to copy to clipboard. Leave empty to copy main program. Refer to the code as $PROGRAM",
+                        "scope": "resource"
+                    },
                     "acmx.configuration.tasks": {
                         "type": "string",
                         "default": "",
@@ -213,4 +219,4 @@
         "md5-file": "^4.0.0",
         "clipboardy": "^2.2.0"
     }
-}
+}

+ 1 - 1
src/core.ts

@@ -338,7 +338,7 @@ function get_checker_path() {
  *
  * @param path
  * @param tcName
- * @param timeout in miliseconds
+ * @param timeout in milliseconds
  */
 export function timedRun(path: string, tcName: string, timeout: number) {
     let tcInput = join(path, TESTCASES, `${tcName}.in`);

+ 18 - 1
src/extension.ts

@@ -1,4 +1,5 @@
 'use strict';
+import * as child_process from 'child_process';
 import { closeSync, copyFileSync, existsSync, openSync, readdirSync, readFileSync, writeFileSync, writeSync } from 'fs';
 import { basename, dirname, extname, join } from 'path';
 import * as vscode from 'vscode';
@@ -351,8 +352,24 @@ async function copySubmissionToClipboard() {
         return;
     }
 
+    let submissionCommand: string | undefined = vscode.workspace.getConfiguration('acmx.configuration', null).get('copyToClipboardCommand');
     let sol = join(path, solFile());
-    let content = readFileSync(sol, "utf8");
+    let content = "";
+
+    if (submissionCommand === undefined || submissionCommand === "") {
+        content = readFileSync(sol, "utf8");
+    } else {
+        submissionCommand = submissionCommand.replace("$PROGRAM", sol);
+        let submissionCommands = submissionCommand.split(' ');
+        let xresult = child_process.spawnSync(submissionCommands[0], submissionCommands.slice(1));
+
+        if (xresult.status !== 0) {
+            vscode.window.showErrorMessage("Fail generating submission.");
+            return;
+        }
+
+        content = xresult.stdout.toString();
+    }
 
     clipboardy.writeSync(content);
 }