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