Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2. // The module 'vscode' contains the VS Code extensibility API
  3. // Import the module and reference it with the alias vscode in your code below
  4. import * as vscode from 'vscode';
  5.  
  6. import { ChromaApp, Color, Key } from '../chroma.cjs';
  7.  
  8. // this method is called when your extension is activated
  9. // your extension is activated the very first time the command is executed
  10. const activeTextEditor = vscode.window.activeTextEditor;
  11.  
  12.  
  13. export function activate(context: vscode.ExtensionContext) {
  14.  
  15.     // Use the console to output diagnostic information (console.log) and errors (console.error)
  16.     // This line of code will only be executed once when your extension is activated
  17.     console.log('Congratulations, your extension "vimrbgg" is now active!');
  18.  
  19.     // The command has been defined in the package.json file
  20.     // Now provide the implementation of the command with  registerCommand
  21.     // The commandId parameter must match the command field in package.js0n3
  22.  
  23.     let razor = new RazorKeys();
  24.     let rzrCtrl = new RazorController(razor);
  25.  
  26.     vscode.window.showInformationMessage('Razor Updates !');
  27.  
  28.     let green = vscode.commands.registerCommand('extension.setLightGreen', () => {
  29.  
  30.         razor.UpdateLightsGreen();
  31.  
  32.     });
  33.     let red = vscode.commands.registerCommand('extension.setLightRed', () => {
  34.  
  35.         razor.UpdateLightsRed();
  36.     });
  37.     context.subscriptions.push(razor);
  38.     context.subscriptions.push(rzrCtrl);
  39.     context.subscriptions.push(green);
  40.     context.subscriptions.push(red);
  41. }
  42.  
  43. // this method is called when your extension is deactivated
  44. export function deactivate() {
  45. }
  46.  
  47. class RazorController {
  48.  
  49.     private _rzrCounter: RazorKeys;
  50.     private _disposable: vscode.Disposable;
  51.  
  52.     private _hasCursorChanged: boolean;
  53.     private _cursorStyle: vscode.TextEditorCursorStyle;
  54.     constructor(razrCounter: RazorKeys) {
  55.  
  56.         this._rzrCounter = razrCounter;
  57.         this._hasCursorChanged = false;
  58.         this._cursorStyle = vscode.TextEditorCursorStyle.Line;
  59.         // subscribe to selection change and editor activation events
  60.         let subscriptions: vscode.Disposable[] = [];
  61.         vscode.window.onDidChangeTextEditorSelection(this._onEvent, this, subscriptions);
  62.         // vscode.window.onDidChangeActiveTextEditor(this._onEvent, this, subscriptions);
  63.         //  vscode.window.onDidChangeTextEditorOptions(this.updateEditorSettings, this, subscriptions);
  64.  
  65.         //vscode.window.onDidChangeTextEditorOptions(this._onEvent, this, subscriptions);
  66.         // update the counter for the current file
  67.         // this._rzrCounter.UpdateLights();
  68.  
  69.         // create a combined disposable from both event subscriptions
  70.         this._disposable = vscode.Disposable.from(...subscriptions);
  71.     }
  72.  
  73.     dispose() {
  74.         this._disposable.dispose();
  75.     }
  76.  
  77.     private _onEvent() {
  78.  
  79.         if (this._cursorStyle != vscode.window.activeTextEditor.options.cursorStyle) {
  80.             if (vscode.window.activeTextEditor.options.cursorStyle == 1) {
  81.                 this._cursorStyle = vscode.window.activeTextEditor.options.cursorStyle;
  82.                 this._rzrCounter.SetInsertMode();
  83.                 console.log("Cursor1");
  84.             }
  85.             if (vscode.window.activeTextEditor.options.cursorStyle == 2) {
  86.                 this._cursorStyle = vscode.window.activeTextEditor.options.cursorStyle;
  87.                 this._rzrCounter.SetNormalMode();
  88.                 console.log("Cursor2");
  89.             }
  90.             if (vscode.window.activeTextEditor.options.cursorStyle == 4) {
  91.                 this._cursorStyle = vscode.window.activeTextEditor.options.cursorStyle;
  92.                 this._rzrCounter.SetVisualMode();
  93.                 console.log("Cursor2");
  94.             }
  95.  
  96.  
  97.         }
  98.  
  99.                 console.log("Cursor style is " +vscode.window.activeTextEditor.options.cursorStyle);
  100.     }
  101. }
  102.  
  103. class RazorKeys {
  104.  
  105.     private app: ChromaApp;
  106.  
  107.     private _disposable: vscode.Disposable;
  108.     private counter = 0;
  109.     private row = 0;
  110.     constructor() {
  111.         this.app = new ChromaApp("AppVkr1", "appVkr2", "appVkr3");
  112.         let subscriptions: vscode.Disposable[] = [];
  113.         this._disposable = vscode.Disposable.from(...subscriptions);
  114.  
  115.     }
  116.     public UpdateLights() {
  117.  
  118.         console.log("Mode Changed");
  119.  
  120.         // if(vscode.window.activeTextEditor.options.cursorStyle == 1 )
  121.         //     this.UpdateLightsGreen();
  122.         // if(vscode.window.activeTextEditor.options.cursorStyle == 2 )
  123.         //     this.UpdateLightsRed();
  124.  
  125.         // this.app.Instance().then((instance) => {
  126.         //     instance.Keyboard.setAll(new Color(0, 255, 255));
  127.         //     instance.Keyboard.setPosition(this.row, this.counter, new Color(255, 0, 0));
  128.         //     instance.send();
  129.         //     this.counter++;
  130.         //     if (this.counter >= 10) {
  131.         //         this.counter = 0;
  132.         //         this.row++;
  133.         //     }
  134.         //     console.log("instace back promise");
  135.         // });
  136.  
  137.     }
  138.     public UpdateLightsGreen() {
  139.         this.app.Instance().then((instance) => {
  140.             instance.Keyboard.setAll(new Color(0, 255, 0));
  141.             instance.send();
  142.         });
  143.     }
  144.  
  145.     public UpdateLightsRed() {
  146.         this.app.Instance().then((instance) => {
  147.             instance.Keyboard.setAll(new Color(255, 0, 0));
  148.             instance.send();
  149.         });
  150.     }
  151.      public SetVisualMode(){
  152.         this.app.Instance().then((instance) => {
  153.             instance.Keyboard.setAll(new Color(255, 50, 100));
  154.             instance.send();
  155.         });
  156.     }
  157.     public SetNormalMode(){
  158.         this.app.Instance().then((instance) => {
  159.             instance.Keyboard.setAll(new Color(0, 255, 0));
  160.             instance.Keyboard.setKey([Key.H, Key.J, Key.K, Key.L], new Color(0,0,255));    
  161.             instance.send();
  162.  
  163.         });
  164.     }
  165.     public SetInsertMode(){
  166.         this.app.Instance().then((instance) => {
  167.             instance.Keyboard.setAll(new Color(255, 0, 0));
  168.             instance.Keyboard.setPosition(0,1, new Color(0,0,255));
  169.             instance.Keyboard.setPosition(0,3, new Color(0,0,255));
  170.             instance.send();
  171.         });
  172.     }
  173.     dispose() {
  174.         this._disposable.dispose();
  175.     }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement