有没有一些c++库/源类似于 boost program_options 但用于 *键盘快捷键自动生成帮助* ?
所以,我有一些带有键绑定的 C++ 源代码,例如:
switch( keypressed )
{
case 'c':
cam_handle->Yaw(min_angle );
break;
case 'd':
cam_handle->Yaw( -min_angle );
break;
case 's':
cam_handle->Pitch(min_angle );
break;
case 'x':
cam_handle->Pitch( -min_angle );
break;
case 'z':
cam_handle->Roll( min_angle );
break;
case 'a':
cam_handle->Roll( -min_angle );
我总是忘记愚蠢的键是什么并且必须猜测,它们可能会改变,或者添加新键等。是否有一些快速的方法来自动生成帮助或“白痴指南”弹出窗口说明了快捷方式是什么?如果有人不知道 boost::program_options 但可以回答,这里有一个例子:
int options(int ac, char ** av, Options& opts) {
// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "Produce help message.")
("width,w", po::value<int>(&opts.frameWidth)->default_value(640),"frame width")
("height,h", po::value<int>(&opts.frameHeight)->default_value(480),"frame height")
("port,p", po::value<string>(&opts.port)->default_value("5001"),"port");
po::variables_map vm;
po::store(po::command_line_parser(ac, av).options(desc).allow_unregistered().run(),vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
return 0;
}
所以,我不必“RTFC”来知道如何使用可执行文件,我只需说“./myapp --help “并且 boost 有很好的自动生成的帮助等等。键盘快捷键映射是否有类似的东西,其中击键取代了命令行标志的作用? (在 C++ 中就是这样。原则上 C 也可以,但我怀疑它是否能像 boost 那样优雅。)
So, I have some c++ source with key bindings like:
switch( keypressed )
{
case 'c':
cam_handle->Yaw(min_angle );
break;
case 'd':
cam_handle->Yaw( -min_angle );
break;
case 's':
cam_handle->Pitch(min_angle );
break;
case 'x':
cam_handle->Pitch( -min_angle );
break;
case 'z':
cam_handle->Roll( min_angle );
break;
case 'a':
cam_handle->Roll( -min_angle );
I always forget what the stupid keys are and have to guess, and they might change, or new keys get added, etc. Is there some fast way to auto-generate help or an "idiot's guide" popup that that says what the short-cuts are? In case someone doesn't know boost::program_options but can answer, here's an example of that:
int options(int ac, char ** av, Options& opts) {
// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "Produce help message.")
("width,w", po::value<int>(&opts.frameWidth)->default_value(640),"frame width")
("height,h", po::value<int>(&opts.frameHeight)->default_value(480),"frame height")
("port,p", po::value<string>(&opts.port)->default_value("5001"),"port");
po::variables_map vm;
po::store(po::command_line_parser(ac, av).options(desc).allow_unregistered().run(),vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
return 0;
}
So, I don't have to "RTFC" to know how to use the executable, I just say "./myapp --help" and boost has nicely auto-generated help and all that. Is there something like this for keyboard shortcut mapping, where the key strokes replace the role of commandline flags? (In C++ that is. In principle C is OK too but I doubt it could be as elegant as the boost stuff. )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,这是两双不同的鞋。如果您想创建并发布有关您的应用程序的文档,我认为通过
--help
选项访问它可能不是最好的选择。对于小程序来说这可能没问题,但是 boost::program_options 肯定不是处理这个问题的最佳方法。如果您想进行
--help
开关,则必须查找main
的argc
和argv
参数code> 函数:我认为,理想的方法是使按键可配置,并将带有相应按键的操作保存到配置文件中,该文件在您的应用程序中进行解释。因此,用户始终可以查看可用于您的应用程序的操作,并且还可以配置它们。
In my opinion these are two different pairs of shoes. If you like to create and ship documentation about your application I think it might not be the best to make it accessible via a
--help
option. It might be okay for small programs, butboost::program_options
is certainly not the best way to deal with this.If you want to make a
--help
switch, you have to look up theargc
andargv
arguments for yourmain
function:I think, the ideal way would be to make the keys configurable and to save the actions with the according keys into a configuration file which gets interpreted in your application. So the user can always see the actions available for your application and can also configure them.