Parcourir la source

Implement idle input notification thats runs every 5s when awaiting for an user input

Lucas de Souza il y a 5 ans
Parent
commit
b0a1ee6bea
3 fichiers modifiés avec 27 ajouts et 2 suppressions
  1. 2 1
      i18n/pt/message.json
  2. 24 1
      js/io/domConsole.js
  3. 1 0
      js/util/config.js

+ 2 - 1
i18n/pt/message.json

@@ -1,5 +1,6 @@
 {
   "test_case_success": "Caso de teste $0: OK",
   "test_case_duration": "Levou $0ms",
-  "test_suite_grade": "A sua solução alcançou $0% da nota."
+  "test_suite_grade": "A sua solução alcançou $0% da nota.",
+  "awaiting_input_message": "O seu programa está em execução e aguardando uma entrada! Digite alguma coisa..."
 }

+ 24 - 1
js/io/domConsole.js

@@ -1,4 +1,5 @@
 import { LocalizedStrings } from "./../services/localizedStringsService";
+import { Config } from "./../util/config";
 
 export class DOMConsole {
 
@@ -21,6 +22,7 @@ export class DOMConsole {
   constructor (elementID) {
     this.input = null;
     this.cursorInterval = null;
+    this.idleInterval = null;
     this.inputDiv = null;
     this.inputCMD = null;
     this.inputSpan = null;
@@ -59,6 +61,10 @@ export class DOMConsole {
     }
     const keyCode = event.which;
     if (keyCode === 13 || this.anyKey) {
+      if(this.idleInterval != null) {
+        clearInterval(this.idleInterval);
+        this.idleInterval = null;
+      }
       let text = this.input.value;
       text = text.replace('[\n\r]+', '');
       this.notifyListeners(text);
@@ -134,6 +140,9 @@ export class DOMConsole {
 
   updateSpanText () {
     this.inputSpan.innerHTML = this.input.value;
+    if(this.idleInterval != null)
+      window.clearInterval(this.idleInterval);
+    this.scheduleNotify()
   }
 
   stopBlinkCaret () {
@@ -232,6 +241,9 @@ export class DOMConsole {
     if(this.cursorInterval != null) {
       clearInterval(this.cursorInterval);
     }
+    if(this.idleInterval != null) {
+      clearInterval(this.idleInterval);
+    }
   }
 
   showInput () {
@@ -251,11 +263,13 @@ export class DOMConsole {
   requestInput (callback, anyKey = false) {
     this.inputListeners.push(callback);
     this.anyKey = anyKey;
+    if(this.idleInterval == null)
+      this.scheduleNotify();
     this.showInput();
   }
 
   sendOutput (text) {
-    const output = ""+text;
+    const output = ""+tthis.inputCMD.click();ext;
     output.split("\n").forEach(t => {
       t = t.replace(/\t/g,'	');
       this.write(t)
@@ -281,4 +295,13 @@ export class DOMConsole {
   hideBtnClick () {
     this.hide();
   }
+
+  notifyIdle () {
+    this.info(LocalizedStrings.getMessage('awaiting_input_message'));
+    this.inputCMD.click();
+  }
+  
+  scheduleNotify () {
+    this.idleInterval = window.setInterval(this.notifyIdle.bind(this), Config.idle_input_interval);
+  }
 }

+ 1 - 0
js/util/config.js

@@ -6,6 +6,7 @@ class ConfigObject {
     this.intConvertRoundMode = 2;
     this.default_lang = 'pt';
     this.enable_type_casting = true;
+    this.idle_input_interval = 5000;
   }
 
   setConfig (opts) {