Simple run start timer

This commit is contained in:
2026-02-08 01:48:28 +01:00
parent 4d0772bc8a
commit 58f86e634b
3 changed files with 65 additions and 21 deletions
+9 -3
View File
@@ -9,13 +9,19 @@
"categories": [
"Other"
],
"activationEvents": [],
"activationEvents": [
"onStartupFinished"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "devrun-vscode.helloWorld",
"title": "Hello World"
"command": "devrun-vscode.startRun",
"title": "DevRun: Start a Run"
},
{
"command": "devrun-vscode.startServer",
"title": "DevRun: Start the run server (for quick run starts)"
}
]
},
+29 -16
View File
@@ -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();
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() {}
+25
View File
@@ -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);
}