00001 #include "HelpControl.h"
00002
00003
00004
00005 ControlBase * HelpControl::activate(MotionManager::MC_ID disp_id, Socket * gui) {
00006 char * fmt=" * ";
00007 if(config->main.use_VT100) {
00008 fmt="\33[1m * \33[0m";
00009 sout->printf("%s","\33[1m* Global commands\33[0m: type these anytime, interpreted directly by Controller\n");
00010 } else
00011 sout->printf("%s","* Global commands: type these anytime, interpreted directly by Controller\n");
00012 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");
00013 sout->printf("%s%s",fmt,"'!reset' - return to the root control\n");
00014 sout->printf("%s%s",fmt,"'!next' - calls doNextItem() of the current control\n");
00015 sout->printf("%s%s",fmt,"'!prev' - calls doPrevItem() of the current control\n");
00016 sout->printf("%s%s",fmt,"'!select' - calls doSelect() of the current control\n");
00017 sout->printf("%s%s",fmt,"'!cancel' - calls doCancel() of the current control\n");
00018 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");
00019 sout->printf("%s%s",fmt,"'!msg text' - broadcasts text as a TextMsgEvent\n");
00020 sout->printf("%s%s",fmt,"'!root text' - - calls ControlBase::takeInput(text) on the root control\n");
00021 sout->printf("%s%s",fmt,"'!hilight [n1 [n2 [...]]]' - hilights zero, one, or more items in the menu\n");
00022 sout->printf("%s%s",fmt,"'!input text' - calls takeInput(text) on the currently hilighted control(s)\n");
00023 sout->printf("%s%s",fmt,"'!set section.key=value' - will be sent to Config::setValue(section,key,value)\n");
00024 sout->printf("%s%s",fmt,"any text not beginning with ! - sent to takeInput() of the current control\n");
00025 report(root,"",maxDepth);
00026 return NullControl::activate(disp_id,gui);
00027 }
00028
00029
00030
00031
00032
00033 void HelpControl::report(ControlBase* r, const std::string& prefix, unsigned int depth_remain) {
00034 if(r==NULL || depth_remain==0)
00035 return;
00036 const std::vector<ControlBase*>& slots=r->getSlots();
00037 const std::string pre=" "+prefix;
00038 unsigned int numlen=1;
00039 if(slots.size()>1)
00040 numlen=(int)(log(slots.size()-1.0)/log(10.0))+1;
00041 #ifdef HelpControl_HTML_
00042 unsigned int ngoodslots=0;
00043 for(unsigned int i=0; i<slots.size(); i++)
00044 if(slots[i]!=NULL)
00045 ngoodslots++;
00046 if(ngoodslots>0)
00047 sout->printf("<ol>\n");
00048 #endif
00049 for(unsigned int i=0; i<slots.size(); i++) {
00050 if(slots[i]==NULL)
00051 continue;
00052 char * fmt;
00053 std::string nm=slots[i]->getName();
00054 std::string desc=slots[i]->getDescription();
00055 unsigned int len=term_width-(prefix.size()+nm.size()+4+numlen);
00056 if((int)len<0)
00057 len=0;
00058 if(len>desc.size())
00059 len=desc.size();
00060 else
00061 while(len>0 && !isspace(desc[len-1])) len--;
00062 #ifdef HelpControl_HTML_
00063 fmt="%s<li value=\"%*d\"><code><b>%s</b>: %s";
00064 #else
00065 if(config->main.use_VT100)
00066 fmt="\33[1m%s%*d. %s\33[0m: %s\n";
00067 else
00068 fmt="%s%*d. %s: %s\n";
00069 #endif
00070 sout->printf(fmt,prefix.c_str(),numlen,i,nm.c_str(),desc.substr(0,len).c_str());
00071 while(len<desc.size() && isspace(desc[len])) len++;
00072 desc=desc.substr(len);
00073 while(desc.size()>0) {
00074 len=term_width-prefix.size();
00075 if((int)len<0)
00076 len=0;
00077 if(len>desc.size())
00078 len=desc.size();
00079 else {
00080 while(len>0 && !isspace(desc[len-1])) len--;
00081 if(len==0)
00082 len=term_width-prefix.size();
00083 if(len>desc.size())
00084 len=desc.size();
00085 }
00086 #ifdef HelpControl_HTML_
00087 sout->printf("\n%s",desc.substr(0,len).c_str());
00088 #else
00089 sout->printf("%s%s\n",std::string(prefix.size(),' ').c_str(),desc.substr(0,len).c_str());
00090 #endif
00091 while(len<desc.size() && isspace(desc[len])) len++;
00092 desc=desc.substr(len);
00093 }
00094 #ifdef HelpControl_HTML_
00095 sout->printf("</code></li>\n");
00096 #endif
00097 report(slots[i],pre,depth_remain-1);
00098 }
00099 #ifdef HelpControl_HTML_
00100 if(ngoodslots>0)
00101 sout->printf("</ol>\n");
00102 #endif
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115