| 
					
				 | 
			
			
				@@ -6,6 +6,7 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include <regex.h> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include <string.h> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include <string> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#include <vector> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include "zf_log.h" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -833,9 +834,16 @@ int mangle(int fd, std::string buffer) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   int mangled = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   int mangled_chars = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   static std::string work; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  static size_t work_size = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   work.assign(buffer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // This should allow us to monitor any memory allocations 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (work.capacity() != work_size) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ZF_LOGD("work cap %lu -> %lu", work_size, work.capacity()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    work_size = work.capacity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   const char *ANSI_CLS = "\x1b[2J"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   size_t pos = buffer.find(ANSI_CLS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -845,6 +853,47 @@ int mangle(int fd, std::string buffer) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Ok, maybe the work string was a bad idea? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  static std::string text; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  static std::vector<int> text_offsets; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  size_t stri; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  text.clear(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  text_offsets.clear(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  for (stri = 0; stri < buffer.size(); ++stri) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    termchar tc = console_char(&console, work[stri]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (tc.in_ansi) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if (tc.ansi != START) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Ok, this is something.  What is it? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ZF_LOGD("ANSI type %d at %lu", tc.ansi, stri); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        switch (tc.ansi) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case CURSOR: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case CLEAR: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OTHER: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          text.append(1, '.'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          text_offsets.push_back(-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case COLOR: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          // text.append(1, ' '); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          // text_offsets.push_back(-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // These should never get out of sync ... 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if (text.size() != text_offsets.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ZF_LOGE("Error: text != text_offsets %lu != %lu", text.size(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                text_offsets.size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      text.append(1, work[stri]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      text_offsets.push_back(stri); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ZF_LOGD_MEM(text.data(), text.size(), "Text Buffer:"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   if (need_render) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     render(fd, buffer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } else { 
			 |