From bbfaecc90c2c3e1f37f7a46de9ae2fbd1ef2e71b Mon Sep 17 00:00:00 2001
From: echicken <>
Date: Fri, 21 Aug 2015 21:32:40 +0000
Subject: [PATCH] Added Frame.dump, Display.dump, because everybody needs to
 take a dump now and then.

Frame.dump returns a 2D array of [row[[column]]] data representing what is
visible in the terminal at the moment.  If a given y,x location has no
data, [y][x] is left undefined. If more than one frame has data at a given
location, the topmost frame's data is returned. Data from frames beneath
non-transparent frames will not be returned.
---
 exec/load/frame.js | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/exec/load/frame.js b/exec/load/frame.js
index 526c71e38e..37ec1f6703 100644
--- a/exec/load/frame.js
+++ b/exec/load/frame.js
@@ -887,6 +887,9 @@ Frame.prototype.invalidate = function() {
 	this.__properties__.display.invalidate();
 	this.refresh();
 }
+Frame.prototype.dump = function() {
+	return this.__properties__.display.dump();
+}
 
 /* console method emulation */
 Frame.prototype.home = function() {
@@ -1476,6 +1479,21 @@ Display.prototype.screenShot = function(file,append) {
 Display.prototype.invalidate = function() {
 	this.__properties__.buffer = {};
 }
+Display.prototype.dump = function() {
+	var arr = [];
+	for(var y = 0; y < this.height; y++) {
+		arr[y] = [];
+		for(var x = 0; x < this.width; x++) {
+			var c = this.__getTopCanvas__(x, y);
+			if(typeof c == "undefined")
+				continue;
+			var d = this.__getData__(c, x, y);
+			if(typeof d.ch != "undefined")
+				arr[y][x] = d;
+		}
+	}
+	return arr;
+}
 
 /* private functions */
 Display.prototype.__updateChar__ = function(x,y/*,data*/) {
-- 
GitLab