From 74b6d9dff9b1f97e87a36852e594a8a6f9f2dedc Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 2 Nov 2016 16:08:13 +0000 Subject: [PATCH] Provide string view of buffers in debug messages --- nodes/core/core/lib/debug/debug-utils.js | 53 ++++++++++++++---------- nodes/core/core/lib/debug/style.css | 8 ++-- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/nodes/core/core/lib/debug/debug-utils.js b/nodes/core/core/lib/debug/debug-utils.js index 3bede1f43..04c81805c 100644 --- a/nodes/core/core/lib/debug/debug-utils.js +++ b/nodes/core/core/lib/debug/debug-utils.js @@ -287,39 +287,46 @@ RED.debug = (function() { if (originalLength > 0) { $(' ').prependTo(header); + var arrayRows = $('
').appendTo(element); makeExpandable(header,function() { if (!key) { - var headerHead = $('').html(typeHint||(type+'['+originalLength+']')).appendTo(header); - if (type === 'buffer') { - // var bufferOpts = $('').appendTo(headerHead); - // //dec hex string - // $('').addClass('selected').html('dec').appendTo(bufferOpts).click(function(e) { - // $(this).addClass('selected').siblings().removeClass('selected'); - // e.preventDefault(); - // e.stopPropagation(); - // }) - // $('').html('hex').appendTo(bufferOpts).click(function(e) { - // $(this).addClass('selected').siblings().removeClass('selected'); - // e.preventDefault(); - // e.stopPropagation(); - // }) - // $('').html('string').appendTo(bufferOpts).click(function(e) { - // $(this).addClass('selected').siblings().removeClass('selected'); - // e.preventDefault(); - // e.stopPropagation(); - // }) + headerHead = $('').html(typeHint||(type+'['+originalLength+']')).appendTo(header); + } + if (type === 'buffer') { + var stringRow = $('').hide().appendTo(element); + var sr = $('
').appendTo(stringRow); + var stringEncoding = ""; + try { + stringEncoding = String.fromCharCode.apply(null, new Uint16Array(data)) + } catch(err) { + console.log(err); } + $('
').html(stringEncoding).appendTo(sr);
+                        var bufferOpts = $('').appendTo(headerHead);
+                        $('').addClass('selected').html('raw').appendTo(bufferOpts).click(function(e) {
+                            if ($(this).text() === 'raw') {
+                                $(this).text('string');
+                                arrayRows.hide();
+                                stringRow.show();
+                            } else {
+                                $(this).text('raw');
+                                arrayRows.show();
+                                stringRow.hide();
+                            }
+                            e.preventDefault();
+                            e.stopPropagation();
+                        })
                     }
                     var row;
                     if (fullLength <= 10) {
                         for (i=0;i