示例#1
0
文件: main.cpp 项目: novopl/nconsole
//--------------------------------------------------------------------//
int main(int argc, char **argv){
  using namespace novo; 
  using boost::format;
  
  novo::add_log_output( "stdout", &novo::stdout );
  //logger()->add_output( new LogStdOut() );
  //logger()->add_output( new LogFileOut("console.log"),  LogLevel::All );

  Console *console = new Console();

  console->add("test", "Test command", [&](const String &args){
    novo::logf("TEST COMMAND:\n");
    CArgs cargs;
    console->tokenize( &cargs, args );
    for( const auto &arg: cargs ){
      novo::logf(str( format(" - %s\n") %arg ));
    }
  });
  console->process_input("cmdlist");
  console->process_input("test arg1 arg2 \"multi arg3\"");
  console->process_input("help");
  console->process_input("help test");
  console->process_input("help wrong test");

  console->remove("test");
  delete console;

  return 0;
}
  virtual int overflow(int c)
  {
    if(pbase() == pptr())
      return 0;

    size_t size = pptr() - pbase();
    console->add(pbase(), size);
      
    if(c != traits_type::eof()) {
      char str[1];
      str[0] = c;
      console->add(str, 1);
    }

    setp(buf, buf + size);

    return 0;
  }