Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",
"version": "2.0.0",

// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

// The tsc compiler is started in watching mode
"isBackground": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
"problemMatcher": "$tsc-watch",
"tasks": [
{
"label": "npm",
"type": "shell",
"command": "npm",
"args": [
"run",
"compile",
"--loglevel",
"silent"
],
"isBackground": true,
"problemMatcher": "$tsc-watch",
"group": {
"_id": "build",
"isDefault": false
}
}
]
}
30 changes: 30 additions & 0 deletions .vscode/tasks.json.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",

// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

// The tsc compiler is started in watching mode
"isBackground": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
"categories": [
"Other"
],
"contributes": {
"configuration": {
"title": "Typing Speed",
"properties": {
"typingSpeed.display": {
"type": "string",
"default": "wpm",
"enum": [
"wpm",
"cpm"
],
"description": "Display typing speed as words per minute (wpm) or characters per minute (cpm)."
}
}
}
},
"activationEvents": [
"*"
],
Expand All @@ -38,6 +54,6 @@
"mocha": "^2.3.3",
"ts-node": "^3.0.4",
"typescript": "^2.0.3",
"vscode": "^1.0.0"
"vscode": "^1.1.37"
}
}
116 changes: 64 additions & 52 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,85 @@
'use strict';
import { Disposable, ExtensionContext, StatusBarAlignment, StatusBarItem, window } from 'vscode';
import RollingArray from './rollingqueue';
"use strict";
import {
Disposable,
ExtensionContext,
StatusBarAlignment,
StatusBarItem,
window,
workspace,
} from "vscode";
import RollingArray from "./rollingqueue";

export function activate(context: ExtensionContext) {
let typingSpeed = new TypingSpeed();
let controller = new TypingSpeedController(typingSpeed);
let typingSpeed = new TypingSpeed();
let controller = new TypingSpeedController(typingSpeed);

context.subscriptions.push(controller);
context.subscriptions.push(typingSpeed);
context.subscriptions.push(controller);
context.subscriptions.push(typingSpeed);
}

class TypingSpeed {
private _keystrokes: RollingArray = new RollingArray(100);
private _statusBarItem: StatusBarItem;
private _lastUpdate: number = 0;

public updateSpeed() {

if (!this._statusBarItem) {
this._statusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
}

const now = Date.now();
if (now - this._lastUpdate > 2000) {
this._keystrokes.clear();
}
this._lastUpdate = now;
this._keystrokes.add(now);

let cpm = 0;
const count = this._keystrokes.size();
if (count > 1) {
const firstTime = this._keystrokes.first();
cpm = count * 60000 / (now - firstTime);
}

this._statusBarItem.text = `$(keyboard) ${cpm.toFixed(1)} cpm`;
this._statusBarItem.show();
private _keystrokes: RollingArray = new RollingArray(100);
private _statusBarItem: StatusBarItem;
private _lastUpdate: number = 0;

public updateSpeed() {
if (!this._statusBarItem) {
this._statusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
}

dispose() {
this._statusBarItem.dispose();
const now = Date.now();
if (now - this._lastUpdate > 2000) {
this._keystrokes.clear();
}
this._lastUpdate = now;
this._keystrokes.add(now);
// Read the configuration option
const config = workspace.getConfiguration("typingSpeed");
const displayType = config.get<string>("display", "wpm");

let cpm = 0;
let wpm = 0;
const count = this._keystrokes.size();
if (count > 1) {
const firstTime = this._keystrokes.first();
cpm = (count * 60000) / (now - firstTime);
wpm = cpm / 5;
}

this._statusBarItem.text = `$(keyboard) ${
displayType === "cpm" ? `${cpm.toFixed(1)} cpm` : `${wpm.toFixed(1)} wpm`
}`;
this._statusBarItem.show();
}

dispose() {
this._statusBarItem.dispose();
}
}

// this method is called when your extension is deactivated
export function deactivate() {
}
export function deactivate() {}

class TypingSpeedController {
private _typingSpeed: TypingSpeed;
private _disposable: Disposable;
private _typingSpeed: TypingSpeed;
private _disposable: Disposable;

constructor(typingSpeed: TypingSpeed) {
this._typingSpeed = typingSpeed;
constructor(typingSpeed: TypingSpeed) {
this._typingSpeed = typingSpeed;

let subscriptions: Disposable[] = [];
window.onDidChangeTextEditorSelection(this._onEvent, this, subscriptions);
let subscriptions: Disposable[] = [];
window.onDidChangeTextEditorSelection(this._onEvent, this, subscriptions);

this._typingSpeed.updateSpeed();
this._typingSpeed.updateSpeed();

this._disposable = Disposable.from(...subscriptions);
}
this._disposable = Disposable.from(...subscriptions);
}

dispose() {
this._disposable.dispose();
}
dispose() {
this._disposable.dispose();
}

private _onEvent() {
this._typingSpeed.updateSpeed();
}
private _onEvent() {
this._typingSpeed.updateSpeed();
}
}