Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

HelpControl.cc

Go to the documentation of this file.
00001 #include "HelpControl.h"
00002 #include "Shared/Config.h"
00003 #include "Wireless/Socket.h"
00004 
00005 //#define HelpControl_HTML_
00006 
00007 ControlBase * HelpControl::activate(MC_ID disp_id, Socket * gui) {
00008   const char * fmt="  * ";
00009   if(config->main.use_VT100) {
00010     fmt="\33[1m  * \33[0m";
00011     sout->printf("%s","\33[1m* Global commands\33[0m: type these anytime, interpreted directly by Controller\n");
00012   } else
00013     sout->printf("%s","* Global commands: type these anytime, interpreted directly by Controller\n");
00014   sout->printf("%s%s",fmt,"'!refresh' - redisplays the current control (handy on first connecting, or\n     when other output has scrolled it off the screen)\n");
00015   sout->printf("%s%s",fmt,"'!reset' - return to the root control\n");
00016   sout->printf("%s%s",fmt,"'!next' - calls doNextItem() of the current control\n");
00017   sout->printf("%s%s",fmt,"'!prev' - calls doPrevItem() of the current control\n");
00018   sout->printf("%s%s",fmt,"'!select' - calls doSelect() of the current control\n");
00019   sout->printf("%s%s",fmt,"'!cancel' - calls doCancel() of the current control\n");
00020   sout->printf("%s%s",fmt,"'!dump_stack' - requests a dump of the current stack of submenus (useful if the GUI (re)connects and thus current robot state is unknown)\n");
00021   sout->printf("%s%s",fmt,"'!msg text' - broadcasts text as a TextMsgEvent\n");
00022   sout->printf("%s%s",fmt,"'!root text' - - calls ControlBase::takeInput(text) on the root control\n");
00023   sout->printf("%s%s",fmt,"'!hilight [n1 [n2 [...]]]' - hilights zero, one, or more items in the menu\n");
00024   sout->printf("%s%s",fmt,"'!input text' - calls takeInput(text) on the currently hilighted control(s)\n");
00025   sout->printf("%s%s",fmt,"'!set section.key=value' - will be sent to Config::setValue(section,key,value)\n");
00026   sout->printf("%s%s",fmt,"any text not beginning with ! - sent to takeInput() of the current control\n");
00027   report(root,"",maxDepth);
00028   return NullControl::activate(disp_id,gui);
00029 }
00030 
00031 //! displays the menu items of @a r and their descriptions, recursing on submenus
00032 /*! @a prefix is what should be displayed before each menu item (like a bullet point)
00033  *  this is itself prefixed by 2 spaces for each level of recursion.  Word wrapping
00034  *  is performed to maintain the clean indenting */
00035 void HelpControl::report(ControlBase* r, const std::string& prefix, unsigned int depth_remain) {
00036   if(r==NULL || depth_remain==0)
00037     return;
00038   const std::vector<ControlBase*>& slots=r->getSlots();
00039   const std::string pre="  "+prefix;
00040   unsigned int numlen=1;
00041   if(slots.size()>1)
00042     numlen=(int)(log(slots.size()-1.0)/log(10.0))+1;
00043 #ifdef HelpControl_HTML_
00044   unsigned int ngoodslots=0;
00045   for(unsigned int i=0; i<slots.size(); i++)
00046     if(slots[i]!=NULL)
00047       ngoodslots++;
00048   if(ngoodslots>0)
00049     sout->printf("<ol>\n");
00050 #endif
00051   for(unsigned int i=0; i<slots.size(); i++) {
00052     if(slots[i]==NULL)
00053       continue;
00054     const char * fmt;
00055     std::string nm=slots[i]->getName();
00056     std::string desc=slots[i]->getDescription();
00057     unsigned int len=term_width-(prefix.size()+nm.size()+4+numlen);
00058     if((int)len<0)
00059       len=0;
00060     if(len>desc.size())
00061       len=desc.size();
00062     else
00063       while(len>0 && !isspace(desc[len-1])) len--;
00064 #ifdef HelpControl_HTML_
00065     fmt="%s<li value=\"%*d\"><code><b>%s</b>: %s";
00066 #else
00067     if(config->main.use_VT100)
00068       fmt="\33[1m%s%*d. %s\33[0m: %s\n";
00069     else
00070       fmt="%s%*d. %s: %s\n";
00071 #endif
00072     sout->printf(fmt,prefix.c_str(),numlen,i,nm.c_str(),desc.substr(0,len).c_str());
00073     while(len<desc.size() && isspace(desc[len])) len++;
00074     desc=desc.substr(len);
00075     while(desc.size()>0) {
00076       len=term_width-prefix.size();
00077       if((int)len<0)
00078         len=0;
00079       if(len>desc.size())
00080         len=desc.size();
00081       else {
00082         while(len>0 && !isspace(desc[len-1])) len--;
00083         if(len==0)
00084           len=term_width-prefix.size();
00085         if(len>desc.size())
00086           len=desc.size();
00087       }
00088 #ifdef HelpControl_HTML_
00089       sout->printf("\n%s",desc.substr(0,len).c_str());
00090 #else
00091       sout->printf("%s%s\n",std::string(prefix.size(),' ').c_str(),desc.substr(0,len).c_str());
00092 #endif
00093       while(len<desc.size() && isspace(desc[len])) len++;
00094       desc=desc.substr(len);
00095     }
00096 #ifdef HelpControl_HTML_
00097     sout->printf("</code></li>\n");
00098 #endif
00099     report(slots[i],pre,depth_remain-1);
00100   }
00101 #ifdef HelpControl_HTML_
00102   if(ngoodslots>0)
00103     sout->printf("</ol>\n");
00104 #endif
00105 }
00106 
00107 /*! @file
00108  * @brief Implements HelpControl, which recurses through the menu system and outputs the name and description of each item
00109  * @author ejt (Creator)
00110  */
00111 

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:41 2016 by Doxygen 1.6.3