Homepage Demos Overview Downloads Tutorials Reference
Credits

HelpControl.cc

Go to the documentation of this file.
00001 #include "HelpControl.h"
00002 
00003 ControlBase * HelpControl::activate(MotionManager::MC_ID disp_id, Socket * gui) {
00004   char * fmt="  * ";
00005   if(config->main.use_VT100) {
00006     fmt="\33[1m  * \33[0m";
00007     sout->printf("%s","\33[1m* Global commands\33[0m: type these anytime, interpreted directly by Controller\n");
00008   } else
00009     sout->printf("%s","* Global commands: type these anytime, interpreted directly by Controller\n");
00010   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");
00011   sout->printf("%s%s",fmt,"'!reset' - return to the root control\n");
00012   sout->printf("%s%s",fmt,"'!next' - calls doNextItem() of the current control\n");
00013   sout->printf("%s%s",fmt,"'!prev' - calls doPrevItem() of the current control\n");
00014   sout->printf("%s%s",fmt,"'!select' - calls doSelect() of the current control\n");
00015   sout->printf("%s%s",fmt,"'!cancel' - calls doCancel() of the current control\n");
00016   sout->printf("%s%s",fmt,"'!msg text' - broadcasts text as a TextMsgEvent\n");
00017   sout->printf("%s%s",fmt,"'!hilight [n1 [n2 [...]]]' - hilights zero, one, or more items in the menu\n");
00018   sout->printf("%s%s",fmt,"'!input text' - calls takeInput(text) on the currently hilighted control(s)\n");
00019   sout->printf("%s%s",fmt,"any text not beginning with ! - sent to takeInput() of the current control\n");
00020   report(root,"",maxDepth);
00021   return NullControl::activate(disp_id,gui);
00022 }
00023 
00024 //! displays the menu items of @a r and their descriptions, recursing on submenus
00025 /*! @a prefix is what should be displayed before each menu item (like a bullet point)
00026  *  this is itself prefixed by 2 spaces for each level of recursion.  Word wrapping
00027  *  is performed to maintain the clean indenting */
00028 void HelpControl::report(ControlBase* r, const std::string& prefix, unsigned int depth_remain) {
00029   if(r==NULL || depth_remain==0)
00030     return;
00031   const std::vector<ControlBase*>& slots=r->getSlots();
00032   const std::string pre="  "+prefix;
00033   unsigned int numlen=1;
00034   if(slots.size()>1)
00035     numlen=(int)(log(slots.size()-1)/log(10))+1;
00036   //sout->printf("<ol>\n");
00037   for(unsigned int i=0; i<slots.size(); i++) {
00038     if(slots[i]==NULL)
00039       continue;
00040     char * fmt;
00041     std::string nm=slots[i]->getName();
00042     std::string desc=slots[i]->getDescription();
00043     unsigned int len=term_width-(prefix.size()+nm.size()+4+numlen);
00044     if((int)len<0)
00045       len=0;
00046     if(len>desc.size())
00047       len=desc.size();
00048     else
00049       while(len>0 && !isspace(desc[len-1])) len--;
00050     if(config->main.use_VT100)
00051       fmt="\33[1m%s%*d. %s\33[0m: %s\n";
00052     else
00053       fmt="%s%*d. %s: %s\n";
00054     //fmt="%s<li><!--%*d--><code><b>%s</b>: %s";
00055     sout->printf(fmt,prefix.c_str(),numlen,i,nm.c_str(),desc.substr(0,len).c_str());
00056     while(len<desc.size() && isspace(desc[len])) len++;
00057     desc=desc.substr(len);
00058     while(desc.size()>0) {
00059       len=term_width-prefix.size();
00060       if((int)len<0)
00061         len=0;
00062       if(len>desc.size())
00063         len=desc.size();
00064       else {
00065         while(len>0 && !isspace(desc[len-1])) len--;
00066         if(len==0)
00067           len=term_width-prefix.size();
00068         if(len>desc.size())
00069           len=desc.size();
00070       }
00071       //sout->printf("\n%s",desc.substr(0,len).c_str());
00072       sout->printf("%s%s\n",std::string(prefix.size(),' ').c_str(),desc.substr(0,len).c_str());
00073       while(len<desc.size() && isspace(desc[len])) len++;
00074       desc=desc.substr(len);
00075     }
00076     //sout->printf("</code></li>\n");
00077     report(slots[i],pre,depth_remain-1);
00078   }
00079   //sout->printf("</ol>\n");
00080 }
00081 
00082 /*! @file
00083  * @brief Implements HelpControl, which recurses through the menu system and outputs the name and description of each item
00084  * @author ejt (Creator)
00085  *
00086  * $Author: ejt $
00087  * $Name: tekkotsu-2_1 $
00088  * $Revision: 1.6 $
00089  * $State: Exp $
00090  * $Date: 2004/01/21 20:18:49 $
00091  */
00092 

Tekkotsu v2.1
Generated Tue Mar 16 23:19:13 2004 by Doxygen 1.3.5