简体   繁体   English

具有非阻塞输入的Editline

[英]Editline with non-blocking input

I use editline library in my program, for user commands input in shell. 我在程序中使用editline库,用于在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. 但是外壳程序除外,该程序具有gui接口,因此我需要在单独的线程中运行editline的readline()函数,因为它会阻塞直到按下Enter键为止。 Is there a way to use readline() function without blocking, so I could avoid separate thread usage? 有没有一种方法可以不阻塞地使用readline()函数,因此可以避免单独使用线程?

Why not making the GUI thread run in a different thread and leave the console input in the main thread. 为什么不让GUI线程在其他线程中运行,而将控制台输入留在主线程中。 You can push events to the GUI thread after reading from command line. 从命令行读取后,可以将事件推送到GUI线程。 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. 如果您的GUI允许您在与主线程不同的线程中运行它,那么这当然起作用。

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? 按下Enter键后,它会清除输入-就像在控制台上键入消息一样? I believe it is much simpler to have everything in the GUI 我相信将所有内容都包含在GUI中要简单得多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM