Simple run start timer
This commit is contained in:
+9
-3
@@ -9,13 +9,19 @@
|
|||||||
"categories": [
|
"categories": [
|
||||||
"Other"
|
"Other"
|
||||||
],
|
],
|
||||||
"activationEvents": [],
|
"activationEvents": [
|
||||||
|
"onStartupFinished"
|
||||||
|
],
|
||||||
"main": "./out/extension.js",
|
"main": "./out/extension.js",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "devrun-vscode.helloWorld",
|
"command": "devrun-vscode.startRun",
|
||||||
"title": "Hello World"
|
"title": "DevRun: Start a Run"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "devrun-vscode.startServer",
|
||||||
|
"title": "DevRun: Start the run server (for quick run starts)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
+29
-16
@@ -1,26 +1,39 @@
|
|||||||
// The module 'vscode' contains the VS Code extensibility API
|
import * as vscode from "vscode";
|
||||||
// Import the module and reference it with the alias vscode in your code below
|
import { startRun } from "./startRun";
|
||||||
import * as vscode from 'vscode';
|
|
||||||
|
|
||||||
// This method is called when your extension is activated
|
|
||||||
// Your extension is activated the very first time the command is executed
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
|
console.log("dev-run Activated");
|
||||||
|
|
||||||
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
const statusBarItem = vscode.window.createStatusBarItem(
|
||||||
// This line of code will only be executed once when your extension is activated
|
vscode.StatusBarAlignment.Left,
|
||||||
console.log('Congratulations, your extension "devrun-vscode" is now active!');
|
10,
|
||||||
|
);
|
||||||
|
|
||||||
// The command has been defined in the package.json file
|
statusBarItem.text = "$(clock) No run yet";
|
||||||
// Now provide the implementation of the command with registerCommand
|
statusBarItem.show();
|
||||||
// The commandId parameter must match the command field in package.json
|
|
||||||
let disposable = vscode.commands.registerCommand('devrun-vscode.helloWorld', () => {
|
let disposable = vscode.commands.registerCommand(
|
||||||
// The code you place here will be executed every time your command is executed
|
"devrun-vscode.startRun",
|
||||||
// Display a message box to the user
|
async () => {
|
||||||
vscode.window.showInformationMessage('Hello World from devrun-vscode!');
|
const problemId = await vscode.window.showInputBox({
|
||||||
|
prompt: "Enter a valid problem ID",
|
||||||
|
placeHolder: "my-problem",
|
||||||
|
validateInput: (text) => {
|
||||||
|
return text.match(/^[a-zA-Z0-9-]+$/)
|
||||||
|
? null
|
||||||
|
: "Must only contain '-' and alphanumeric characters";
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!problemId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
startRun(statusBarItem, problemId);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
context.subscriptions.push(disposable);
|
context.subscriptions.push(disposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method is called when your extension is deactivated
|
|
||||||
export function deactivate() {}
|
export function deactivate() {}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import * as vscode from "vscode";
|
||||||
|
|
||||||
|
export async function startRun(
|
||||||
|
statusBarItem: vscode.StatusBarItem,
|
||||||
|
problemId: string,
|
||||||
|
) {
|
||||||
|
const mode = await vscode.window.showQuickPick(["any%", "100%"], {
|
||||||
|
placeHolder: "Select a mode",
|
||||||
|
canPickMany: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
let start = Date.now();
|
||||||
|
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
const elapsed = Date.now() - start;
|
||||||
|
|
||||||
|
const minutes = Math.floor(elapsed / 60000);
|
||||||
|
const seconds = Math.floor((elapsed % 60000) / 1000);
|
||||||
|
const hundredths = Math.floor((elapsed % 1000) / 10);
|
||||||
|
|
||||||
|
statusBarItem.text = `$(clock) ${minutes}:${seconds.toString().padStart(2, "0")}.${hundredths
|
||||||
|
.toString()
|
||||||
|
.padStart(2, "0")}`;
|
||||||
|
}, 50);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user