事件驱动的控制台用户界面
我正在编写一个带有基于控制台的用户界面(在客户端)的服务器客户端应用程序。用户会看到提示并可以输入命令。另外,服务器会时不时地发出一条消息,客户端应处理并打印出相关信息。您能否给我一些关于如何建模/实现此类用户界面的建议或分享教程的链接?
I'm writing a server-client application with console based user interface (on the client side). The user is presented with a prompt and has the possibility to type in commands. Also, from time to time, the server will send out a message that the client should process and print out information about. Could you give me a piece of advice as to how go about modelling/implementing this type of user interface or share a link to a tutorial?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于提示相关的任务,我建议 jline,它提供历史记录、自动完成等...
其他考虑因素可能包括:有多复杂是命令吗?起草一些语法。您是否需要一个合适的解析器来实现它们,或者正则表达式就足够了?即使您需要一个解析器,手写的解析器是否可以胜任这项工作?
客户端和服务器如何连接?它们之间有什么协议?每种方式可以设置的草案规范。我建议使用 Netty 来实现网络协议,但也许你可以使用一些现成的 RPC (< a href="https://code.google.com/apis/protocolbuffers/" rel="nofollow">Protobuff,Thrift、Avro)
哪部分工作在哪里完成?让客户端变得轻量级可能是个好主意,但也许某些性能/带宽考虑因素需要更智能的客户端?
For prompt related tasks I suggest jline, it provides history, autocompletion etc...
Other considerations might include: how complex are the commands? Draft some grammar. Do you need a proper parser to implement them, or regex would suffice? Even if you need a parser is some hand written one OK for the job?
How are client and a server connected? What protocol sits between them? Draft spec of what could be set each way. I would recommend Netty for implementing network protocols, but maybe you could go with some of the shelf RPC's (Protobuff, Thrift, Avro)
What part of work is done where? Making a client as lightweight is probably good idea, but maybe some performance/bandwidth considerations call for a bit smarter client?
也许这个库 - http://www.pitman.co.za/projects/charva /index.html 您可能会感兴趣。
Maybe this library - http://www.pitman.co.za/projects/charva/index.html could be interesting for you.