具有非阻塞输入的编辑行
我在程序中使用 editline 库,用于在 shell 中输入用户命令。但是除了shell之外,程序有一个gui界面,所以我需要在单独的线程中运行editline的readline()函数,因为它会阻塞直到按下Enter键。有没有办法在不阻塞的情况下使用 readline() 函数,这样我就可以避免单独的线程使用?
I use editline library in my program, for user commands input in shell. But becides shell, program have a gui interface, so I need to run editline's readline() function in separate thread, because it blocks until Enter pressed. Is there a way to use readline() function without blocking, so I could avoid separate thread usage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不让 GUI 线程在不同的线程中运行并将控制台输入保留在主线程中。从命令行读取事件后,您可以将事件推送到 GUI 线程。我认为这要简单得多。
当然,如果您的 GUI 允许您在与主线程不同的线程中运行它,那么这当然有效。
稍后编辑:您不能创建一个文本控件/窗口并从那里获取输入吗?一旦你按下 Enter 键,它就会清除输入 - 就像在控制台上输入消息一样?我相信将所有内容都放在 GUI 中要简单得多
Why not making the GUI thread run in a different thread and leave the console input in the main thread. You can push events to the GUI thread after reading from command line. It is much simpler in my opinion.
This works of course if your GUI allows you to run it in a different thread than the main one.
LATER EDIT: Couldn't you just create a text control/window and take the input from there? Once you press Enter it clears input - just like typing messages at a console? I believe it is much simpler to have everything in the GUI