Browse Source

Fixed issue #4 with tangler.

The tangler was getting lost if the character
after the word was ANSI.  (index -1).

render had some missing - values for MYSTIC[].
(Code is unused, but still needed to be fixed!)

Update CMakelists so changing a comment moves
the debug buffers off and on.

CharMan::~CharMan diagnostics() for the win!
bugz 4 years ago
parent
commit
d5bf27ace9
3 changed files with 21 additions and 9 deletions
  1. 1 0
      CMakeLists.txt
  2. 17 6
      charman.cpp
  3. 3 3
      render.cpp

+ 1 - 0
CMakeLists.txt

@@ -41,6 +41,7 @@ set(CMAKE_CXX_EXTENSIONS ON)
 # This creates HUGE log files.   Not for production!
 
 set(DISABLE_BUFFER_DEBUG ON CACHE BOOL "Turn off buffer debugging" FORCE)
+# set(DISABLE_BUFFER_DEBUG OFF CACHE BOOL "Turn off buffer debugging" FORCE)
 
 # Always disable in Release build.
 if((CMAKE_BUILD_TYPE STREQUAL Release) OR (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo))

+ 17 - 6
charman.cpp

@@ -1,11 +1,11 @@
+#include "charman.h"
+#include "render.h"
+#include "utils.h"
+#include "zf_log.h"
 #include <ctype.h>
 #include <regex>
 #include <string>
 #include <vector>
-#include "charman.h"
-#include "utils.h"
-#include "zf_log.h"
-#include "render.h"
 
 void CharMan::validate(void) {
   // Control buffer debugging output.
@@ -109,9 +109,18 @@ void CharMan::insert(int pos, std::string str) {
     // vector is holding.
     idx = this->text_offsets[pos - 1] + 1;
     ZF_LOGE("Use %d for idx", idx);
-  } else
+  } else {
     idx = this->text_offsets[pos];
 
+    // What happens if pos is pointing at color code?  Or ANSI cursor movement?
+    // (that follows text)
+
+    if (idx == -1) {
+      idx = this->text_offsets[pos - 1] + 1;
+      ZF_LOGE("-1 take 2: %d", idx);
+    }
+  }
+
   // ZF_LOGE("insert( POS %d, LEN %d, IDX %d, %s)", pos, len, idx, str.c_str());
   // diagnostics();
   std::string blank(len, ' ');
@@ -231,7 +240,8 @@ int CharMan::word_tangler(std::pair<int, int> pos_len) {
     int r = 1; // randint(2) + 1;
 
     buffer << TRIGGER "P1" TRIGGER "R" << r;
-    r = randint(3) + 1; // This will cause us to speed up regarding render speed. (reducing delay for callers using the bbs)
+    r = randint(3) + 1; // This will cause us to speed up regarding render
+                        // speed. (reducing delay for callers using the bbs)
     buffer << TRIGGER "S" << r;
     tangle = buffer.str();
     std::string reset = TRIGGER "R0" TRIGGER "S0";
@@ -295,4 +305,5 @@ CharMan::CharMan(std::string &buffer, std::string &work, std::string &text,
 CharMan::~CharMan() {
   ZF_LOGD("~CharMan");
   // validate();
+  // diagnostics();
 }

+ 3 - 3
render.cpp

@@ -78,7 +78,7 @@ void Render::color(int color) {
   case 13:
   case 14:
   case 15:
-    oss << "\x1b[0;1;" << MYSTIC[color] + 30 << "m";
+    oss << "\x1b[0;1;" << MYSTIC[color - 8] + 30 << "m";
     break;
   case 16:
   case 17:
@@ -88,7 +88,7 @@ void Render::color(int color) {
   case 21:
   case 22:
   case 23:
-    oss << "\x1b[" << MYSTIC[color] + 40 << "m";
+    oss << "\x1b[" << MYSTIC[color - 16] + 40 << "m";
     break;
   case 24:
   case 25:
@@ -98,7 +98,7 @@ void Render::color(int color) {
   case 29:
   case 30:
   case 31:
-    oss << "\x1b[5;" << MYSTIC[color] + 40 << "m";
+    oss << "\x1b[5;" << MYSTIC[color - 24] + 40 << "m";
     break;
   default:
     break;