[gjs: 1/2] Add list command to debugger




commit db23d723153401521cc5411338cdedbc7937daff
Author: Nasah Kuma <nasahnash19 gmail com>
Date:   Thu Feb 18 22:07:20 2021 +0000

    Add list command to debugger

 installed-tests/debugger/list.debugger        |  1 +
 installed-tests/debugger/list.debugger.output |  9 +++++----
 modules/script/_bootstrap/debugger.js         | 17 +++++++++++++----
 3 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/installed-tests/debugger/list.debugger b/installed-tests/debugger/list.debugger
index 0a776dbe..fa97b994 100644
--- a/installed-tests/debugger/list.debugger
+++ b/installed-tests/debugger/list.debugger
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
 # SPDX-FileCopyrightText: 2021 Mantoh Nasah Kuma <nasahnash20 gmail com>
+set colors false
 list
 list 4
 list 11
diff --git a/installed-tests/debugger/list.debugger.output b/installed-tests/debugger/list.debugger.output
index 62a6d307..ce7857ab 100644
--- a/installed-tests/debugger/list.debugger.output
+++ b/installed-tests/debugger/list.debugger.output
@@ -1,18 +1,19 @@
 GJS debugger. Type "help" for help
 db> # SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
 db> # SPDX-FileCopyrightText: 2021 Mantoh Nasah Kuma <nasahnash20 gmail com>
+db> set colors false
 db> list
    6       else if (a === undefined || b === undefined)
    7           return undefined;
    8       else
    9           return a / b;
    10  }
-  *11      divide();
+  *11  divide();
 db> list 4
    1   // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
    2   // SPDX-FileCopyrightText: 2021 Mantoh Nasah Kuma <nasahnash20 gmail com>
    3   function divide(a, b) {
-  *4           if (b === 0)
+  *4       if (b === 0)
    5           return undefined;
    6       else if (a === undefined || b === undefined)
    7           return undefined;
@@ -24,7 +25,7 @@ db> list 11
    8       else
    9           return a / b;
    10  }
-  *11      divide();
+  *11  divide();
 db> list 12
    7           return undefined;
    8       else
@@ -47,7 +48,7 @@ db> list
    1   // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
    2   // SPDX-FileCopyrightText: 2021 Mantoh Nasah Kuma <nasahnash20 gmail com>
    3   function divide(a, b) {
-  *4           if (b === 0)
+  *4       if (b === 0)
    5           return undefined;
    6       else if (a === undefined || b === undefined)
    7           return undefined;
diff --git a/modules/script/_bootstrap/debugger.js b/modules/script/_bootstrap/debugger.js
index f6771f1a..8bb2f8f8 100644
--- a/modules/script/_bootstrap/debugger.js
+++ b/modules/script/_bootstrap/debugger.js
@@ -21,7 +21,7 @@ var topFrame = null;
 var debuggeeValues = {};
 var nextDebuggeeValueIndex = 1;
 var lastExc = null;
-var options = {pretty: true};
+var options = {pretty: true, colors: true};
 var breakpoints = [undefined];  // Breakpoint numbers start at 1
 
 // Cleanup functions to run when we next re-enter the repl.
@@ -260,10 +260,12 @@ function printSurroundingLines(currentLine = 1) {
     let maxLineLimit = Math.min(lastLine, currentLine + 5);
     let minLineLimit = Math.max(1, currentLine - 5);
     for (let i = minLineLimit; i < maxLineLimit + 1; i++) {
-        if (i === currentLine)
-            print(`  *\x1b[1m${i}\t${sourceLines[i - 1]}\x1b[0m`);
-        else
+        if (i === currentLine) {
+            const code = colorCode('1');
+            print(`  *${code[0]}${i}\t${sourceLines[i - 1]}${code[1]}`);
+        } else {
             print(`   ${i}\t${sourceLines[i - 1]}`);
+        }
     }
 }
 
@@ -273,6 +275,12 @@ listCommand.helpText = `USAGE
 PARAMETERS
     -option : option name. Allowed options are: line number`;
 
+function colorCode(codeNumber) {
+    if (options.colors === true)
+        return [`\x1b[${codeNumber}m`, '\x1b[0m'];
+    else
+        return ['', ''];
+}
 function setCommand(rest) {
     var space = rest.indexOf(' ');
     if (space === -1) {
@@ -299,6 +307,7 @@ setCommand.helpText = `USAGE
 PARAMETERS
     · option: option name. Allowed options are:
         · pretty: set print mode to pretty or brief. Allowed value true or false
+        · colors: set printing with colors to true or false.
     · value: option value`;
 
 function splitPrintOptions(s, style) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]