Simple run start timer
This commit is contained in:
+31
-18
@@ -1,26 +1,39 @@
|
||||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
import * as vscode from 'vscode';
|
||||
import * as vscode from "vscode";
|
||||
import { startRun } from "./startRun";
|
||||
|
||||
// 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) {
|
||||
console.log("dev-run Activated");
|
||||
|
||||
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||||
// This line of code will only be executed once when your extension is activated
|
||||
console.log('Congratulations, your extension "devrun-vscode" is now active!');
|
||||
const statusBarItem = vscode.window.createStatusBarItem(
|
||||
vscode.StatusBarAlignment.Left,
|
||||
10,
|
||||
);
|
||||
|
||||
// The command has been defined in the package.json file
|
||||
// Now provide the implementation of the command with registerCommand
|
||||
// The commandId parameter must match the command field in package.json
|
||||
let disposable = vscode.commands.registerCommand('devrun-vscode.helloWorld', () => {
|
||||
// The code you place here will be executed every time your command is executed
|
||||
// Display a message box to the user
|
||||
vscode.window.showInformationMessage('Hello World from devrun-vscode!');
|
||||
});
|
||||
statusBarItem.text = "$(clock) No run yet";
|
||||
statusBarItem.show();
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
let disposable = vscode.commands.registerCommand(
|
||||
"devrun-vscode.startRun",
|
||||
async () => {
|
||||
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);
|
||||
}
|
||||
|
||||
// This method is called when your extension is deactivated
|
||||
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