Prechádzať zdrojové kódy

Updating prompts with color. Display report.

Steve Thielemann 3 rokov pred
rodič
commit
61a00e04fe
5 zmenil súbory, kde vykonal 139 pridanie a 48 odobranie
  1. 33 0
      ansicolor.cpp
  2. 2 0
      ansicolor.h
  3. 99 43
      director.cpp
  4. 4 4
      dispatchers.cpp
  5. 1 1
      scripts.cpp

+ 33 - 0
ansicolor.cpp

@@ -68,6 +68,39 @@ ANSIColor::ANSIColor(COLOR f, ATTR a1, ATTR a2) : ANSIColor() {
   Attr(a2);
 }
 
+ANSIColor::ANSIColor(std::initializer_list<int> il) : ANSIColor() {
+  for (auto const &i : il) {
+    switch (i) {
+      case 1:
+        bold = 1;
+        break;
+      case 5:
+        blink = 1;
+        break;
+      case 30:
+      case 31:
+      case 32:
+      case 33:
+      case 34:
+      case 35:
+      case 36:
+      case 37:
+        fg = (COLOR)(i - 30);
+        break;
+      case 40:
+      case 41:
+      case 42:
+      case 43:
+      case 44:
+      case 45:
+      case 46:
+      case 47:
+        bg = (COLOR)(i - 40);
+        break;
+    }
+  }
+}
+
 /**
  * Construct a new ANSIColor::ANSIColor object
  * with a foreground and background color.

+ 2 - 0
ansicolor.h

@@ -84,6 +84,7 @@ public:
   ANSIColor(COLOR f, COLOR b);
   ANSIColor(COLOR f, COLOR b, ATTR a);
   ANSIColor(COLOR f, COLOR b, ATTR a1, ATTR a2);
+  ANSIColor(std::initializer_list<int> il);
   /*
   ANSIColor(int c1);
   ANSIColor(int c1, int c2);
@@ -95,6 +96,7 @@ public:
   void setFg(COLOR f);
   void setFg(COLOR f, ATTR a);
   void setBg(COLOR b);
+
   /**
    * Get the foreground color
    * @return COLOR

+ 99 - 43
director.cpp

@@ -72,9 +72,8 @@ void Director::client_input(const std::string &input) {
       ANSIColor c1(COLOR::CYAN, ATTR::BOLD);
       ANSIColor c2(COLOR::WHITE, ATTR::BOLD);
 
-      to_client(std::string("\n\r") + c1() + "I'd choose " +
-                c2() + "`T`" + c1() +
-                ", but that's how I was coded.\n\r");
+      to_client(std::string("\n\r") + c1() + "I'd choose " + c2() + "`T`" +
+                c1() + ", but that's how I was coded.\n\r");
       //          "\n\r\x1b[1;36mI'd choose \x1b[1;37m`T`\x1b[1;36m, but "
       //          "that's how I was coded.\n\r");
 
@@ -85,8 +84,7 @@ void Director::client_input(const std::string &input) {
     // easter-egg
     if (prompt == "[Pause]") {
       ANSIColor c1(COLOR::CYAN, ATTR::BOLD);
-      to_client(std::string(" ") + c1() + "PAWS" + reset() +
-                "\n\r");
+      to_client(std::string(" ") + c1() + "PAWS" + reset() + "\n\r");
       to_client(current_raw_prompt);
       return;
     }
@@ -139,12 +137,16 @@ void Director::server_line(const std::string &line,
       if (!galaxy.config["display_lines"]) {
         galaxy.config["display_lines"] = 20;
       }
+
       galaxy.meta["help"]["display_lines"] =
           "Number of report lines to display";
+
       if (!galaxy.config["burnt_percent"]) {
         galaxy.config["burnt_percent"] = 40;
       }
-      galaxy.meta["help"]["burnt_percent"] = "Ignore ports below this percent";
+
+      galaxy.meta["help"]["burnt_percent"] =
+          "Don't display ports in report below this percent";
     }
     // not needed (handled by above Game Server check).
     if (ch == 'Q') {
@@ -223,11 +225,6 @@ void Director::server_line(const std::string &line,
     SL_parser(line);
   }
 
-  /*
-  if (emit_server_line) {
-    emit_server_line(line);
-  }
-   */
   if (chain) {
     chain->server_line(line, raw_line);
   }
@@ -253,7 +250,7 @@ void Director::server_prompt(const std::string &prompt,
       after = prompt.find("] (?=Help)");
       sector_text = prompt.substr(before, after - before);
       current_sector = stoi(sector_text);
-      BUGZ_LOG(fatal) << "Sector: " << sector_text;
+      BUGZ_LOG(info) << "current_sector = " << current_sector;
     }
   }
 
@@ -270,14 +267,21 @@ void Director::build_menu(void) {
   ANSIColor bcolor(COLOR::YELLOW, COLOR::BLUE, ATTR::BOLD);
   ANSIColor tcolor(COLOR::WHITE, COLOR::BLUE, ATTR::BOLD);
   ANSIColor mocolor(COLOR::CYAN, ATTR::BOLD);
-  md->menu_box_color = bcolor(); // "\x1b[1;33;44m";
-  md->menu_text_color = tcolor(); // "\x1b[1;37;44m";
+  md->menu_box_color = bcolor();   // "\x1b[1;33;44m";
+  md->menu_text_color = tcolor();  // "\x1b[1;37;44m";
   md->menu_title = "Proxy Menu";
-  md->menu_options_color = mocolor(); // "\x1b[1;36;40m";
+  md->menu_options_color = mocolor();  // "\x1b[1;36;40m";
 
-  md->menu_prompt =
-      "\x1b[0;31;40m\xdb\xb2\xb1\xb0 \x1b[31;40mRED "
-      "\x1b[32;40mGREEN\x1b[30;42m\xdb\xb2\xb1\xb0 \x1b[0m : ";
+  ANSIColor by{1, 33};
+  ANSIColor cyan{36};
+  ANSIColor bg{1, 32};
+  std::string prompt = by() + "M" + cyan() + "ain " + by() + "P" + cyan() +
+                       "roxy " + bg() + "=>" + reset() + " ";
+
+  md->menu_prompt = prompt;  // "Main Proxy => ";
+
+  // "\x1b[0;31;40m\xdb\xb2\xb1\xb0 \x1b[31;40mRED "
+  // "\x1b[32;40mGREEN\x1b[30;42m\xdb\xb2\xb1\xb0 \x1b[0m : ";
   md->lazy = true;
   md->menu = {{"C", "Configure"},
               {"D", "Display Report"},
@@ -372,20 +376,37 @@ void Director::menu_choice(void) {
           const int per_line = 5;
           int count = 0;
           int line = 0;
+          std::string display_line;
+
+          ANSIColor by{1, 33};
+          ANSIColor cyan{36};
+          ANSIColor bg{1, 32};
+          ANSIColor bb{1, 34};
+
           for (auto const &ppt : pptv) {
-            output = str(boost::format("%1$5d:%2$-5d(%3$d) ") % ppt.s1 %
-                         ppt.s2 % ppt.type);
-            to_client(output);
+            output =
+                str(boost::format("%1%%2$5d%3%:%4%%5$-5d%3%(%6%%7$d%3%) ") %
+                    by() % ppt.s1 % cyan() % bg() % ppt.s2 % bb() % ppt.type);
+            display_line.append(output);
+
             ++count;
             if (count == per_line) {
               count = 0;
-              to_client("\n\r");
+              display_line.append("\n\r");
+              to_client(display_line);
+              display_line.clear();
               ++line;
             }
 
             if (line == max_display) break;
           }
-          if (count != 0) to_client("\n\r");
+
+          if (count != 0) {
+            display_line.append("\n\r");
+            to_client(display_line);
+            display_line.clear();
+          }
+
           // We got < 5 lines, and max_display is > 5.  Offer suggestion:
           if ((line < 5) && (max_display > 5)) {
             // suggestion:
@@ -465,12 +486,20 @@ MenuDispatch *Director::init_scripts_menu(void) {
     md->menu_title = "Scripts Menu";
     md->menu_options_color = "\x1b[1;32;40m";
     md->lazy = false;
-    md->menu_prompt = " SCRIPT : ";
+
+    ANSIColor by{1, 33};
+    ANSIColor cyan{36};
+    ANSIColor bg{1, 32};
+    std::string prompt = by() + "S" + cyan() + "cript " + by() + "M" + cyan() +
+                         "enu " + bg() + "=>" + reset() + " ";
+
+    md->menu_prompt = prompt;  // " SCRIPT : ";
     md->menu = {{"!", "Terror"},
                 {"T", "Trade"},
                 {"S", "Safe Move"},
                 {"C", "Closest Trade"},
-                {"U", "Upgrade Planet Pants"}};
+                {"U", "Upgrade Planet Pants"},
+                {"X", "Exit Scripts"}};
     md->setNotify([this]() { this->scripts_done(); });
     return md;
   }
@@ -551,6 +580,11 @@ void Director::scripts_done(void) {
             to_client("I don't see any best trades.\n\r");
           }
         } break;
+        case 'Q':
+          chain = main_menu;
+          main_menu->activate();
+          return;
+          break;
       }
     }
   }
@@ -574,7 +608,14 @@ InputDispatch *Director::init_config_input(void) {
   if (config_input) {
     // Yes, it has been setup before.
     id = dynamic_cast<InputDispatch *>(&(*config_input));
-    id->prompt = "Config => ";
+
+    ANSIColor by{1, 33};
+    ANSIColor cyan{36};
+    ANSIColor bg{1, 32};
+    std::string prompt =
+        by() + "C" + cyan() + "onfig " + bg() + "=>" + reset() + " ";
+    id->prompt = prompt;  // "Config => ";
+    id->numeric = true;
     id->max_length = 3;
     config_item.clear();
     return id;
@@ -582,7 +623,13 @@ InputDispatch *Director::init_config_input(void) {
     // set it up
     config_input = std::make_shared<InputDispatch>(*this);
     id = static_cast<InputDispatch *>(&(*config_input));
-    id->prompt = "Config => ";
+    ANSIColor by{1, 33};
+    ANSIColor cyan{36};
+    ANSIColor bg{1, 32};
+    std::string prompt =
+        by() + "C" + cyan() + "onfig " + bg() + "=>" + reset() + " ";
+    id->prompt = prompt;  // "Config => ";
+    id->numeric = true;
     id->max_length = 3;
     id->setNotify([this]() { this->config_have_input(); });
     config_item.clear();
@@ -601,13 +648,21 @@ void Director::config_edit(void) {
   }
   // to_client("Configuration:\n\r");
   int item = 1;
+  ANSIColor number(COLOR::CYAN);
+  ANSIColor key(COLOR::GREEN, ATTR::BOLD);
+  ANSIColor value(COLOR::BLUE, ATTR::BOLD);
+
   for (auto const &cfg : galaxy.config) {
-    std::string output = str(boost::format("%1$2d %2$20s: %3$s\n\r") % item %
-                             cfg.first % cfg.second);
+    std::string output =
+        str(boost::format("%1%%2$2d %3%%4$20s: %5%%6$s%7%\n\r") % number() %
+            item % key() % cfg.first % value() % cfg.second % reset());
     to_client(output);
     ++item;
   }
-  to_client("Enter number to edit, blank to exit.\n\r");
+  std::string message =
+      number() + "Enter number to edit, " + key() + "blank to exit.\n\r";
+  // to_client("Enter number to edit, blank to exit.\n\r");
+  to_client(message);
 
   // setup call to config_input:
   InputDispatch *id = init_config_input();
@@ -633,19 +688,11 @@ void Director::config_have_input(void) {
       config_input.reset();
       return;
     } else {
-      int item;
-      try {
-        item = stoi(id->input);
-      } catch (const std::invalid_argument &e) {
-        BUGZ_LOG(fatal) << e.what();
-        item = 0;
-      } catch (const std::out_of_range &e) {
-        BUGZ_LOG(fatal) << e.what();
-        item = 0;
-      }
+      int item = sstoi(id->input);
 
       if ((item < 1) || (item > (int)galaxy.config.size())) {
         // selection out of range - redisplay config menu
+        to_client("What?  I didn't see that item.\n\r");
         config_edit();
         return;
       } else {
@@ -654,14 +701,23 @@ void Director::config_have_input(void) {
         for (auto const &c : config) {
           if (pos == item) {
             // got it!
+            ANSIColor key(COLOR::GREEN, ATTR::BOLD);
+            ANSIColor value(COLOR::BLUE, ATTR::BOLD);
 
             config_item = c.first.as<std::string>();
             std::string output =
-                str(boost::format("%1% : %2%\n\r") % config_item %
-                    galaxy.meta["help"][config_item]);
+                str(boost::format("%1%%2% : %3%%4%\n\r") % key() % config_item %
+                    value() % galaxy.meta["help"][config_item]);
             to_client(output);
             id->max_length = 30;
-            id->prompt = "Change to => ";
+            id->numeric = false;
+
+            ANSIColor by{1, 33};
+            ANSIColor cyan{36};
+            ANSIColor bg{1, 32};
+            std::string prompt =
+                by() + "C" + cyan() + "hange to " + bg() + "=>" + reset() + " ";
+            id->prompt = prompt;
             id->activate();
             return;
           };

+ 4 - 4
dispatchers.cpp

@@ -638,6 +638,10 @@ TraderDispatch::TraderDispatch(Director &d) : Dispatch(d) {
   BUGZ_LOG(fatal) << "TraderDispatch()";
   state = 0;
   success = false;
+  director.galaxy.meta["help"]["stop_percent"] =
+      "ScriptTrader stop trading if below this percent.";
+  director.galaxy.meta["help"]["trade_end_empty"] =
+      "ScriptTrader end trading with empty holds? Y/N";
 };
 
 TraderDispatch::~TraderDispatch() { BUGZ_LOG(fatal) << "~TraderDispatch()"; }
@@ -676,8 +680,6 @@ void TraderDispatch::activate(void) {
   state = 1;
   percent = 5.0;
   to_server("I");
-  director.galaxy.meta["help"]["stop_percent"] =
-      "ScriptTrader stop trading if below this percent.";
 
   if (director.galaxy.config["stop_percent"]) {
     stop_percent = director.galaxy.config["stop_percent"].as<int>();
@@ -685,8 +687,6 @@ void TraderDispatch::activate(void) {
     stop_percent = 25;
     director.galaxy.config["stop_percent"] = stop_percent;
   }
-  director.galaxy.meta["help"]["trade_end_empty"] =
-      "ScriptTrader end trades with empty holds? Y/N";
 
   if (director.galaxy.config["trade_end_empty"]) {
     std::string tee =

+ 1 - 1
scripts.cpp

@@ -44,7 +44,7 @@ void ScriptTerror::activate(void) {
     old_trade_end_empty = "Y";
   }
   director.galaxy.config["trade_end_empty"] = "Y";
-
+  
   // Step 0:  Get ship information / # of holds
   max_loops = loops = -1;
   to_server("I");