You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce eventmux callback function for linenoise
In the previous version of console implementation, we tried to integrate
tiny-web-server to enable the ability of processing commands from web
requests. As the result, the package linenoise which is responsible for
command-line auto-complete needs to be disabled during the running time
of tiny-web-server. Because the main loop in "line_edit()" function in
linenoise doesn't have the ability to handle web requests correctly.
When we start the web server, we use "cmd_select" in console.c and use
"select" function to monitor web socket file descriptor and stdin_fd at
the same time. I re-design the control flow of web request and
command-line input by implement the function "web_eventmux()", and
register it as a hook function of type "line_eventmux_callback_t"
inside linenoise package. As the result, we can utilize function inside
the main loop of linenoise which is located inside the function
"line_edit()".
"web_eventmux()" is a function which use the function "select()" to
monitor both input file descriptor and web file descriptor and modify
"line_edit()" to use "eventmux_callback()" so we can process
command-line input as normal and provide the command-line auto-complete
feature alongside with the abitlity to deal with inputs from different
input sources, such as web request.
One may wonder why don't we simply modify the function "line_edit()",
the reason is that linenoise is an upstream package so we only want to
do the miminal changes to this package.
0 commit comments