c - What are some standard design methods to add GUI to a command line app? - Software Engineering Stack Exchange
Mon Jan 17 2022 22:19:04 GMT+0000 (Coordinated Universal Time)
Saved by
@akshay99
Usually, this can be solved by writing a GUI front-end that builds a command line. At that point you simply call the old CLI "main()" function with the arguments in the appropriate order.
What you need to do then, depends on the output. You might do well by wrapping all printf()'s in a generic output variadic function, that in the CLI version will just pass control to printf while in the GUI version sends output to a scrolldown log window or something like that.
This way, the CLI application is mostly unchanged and the GUI front-end, while losing in efficiency, remains loosely coupled and can be maintained independently (in some cases, a mockup - or even a real alternative to the GUI - might be an independent application that then spawns the CLI binary with the proper arguments; sort of what you can do with AutoIt on Windows, so to speak).
But this strongly depends on what the application actually does. This approach can still be pursued to a greater or lesser extent, but it might become awkward if, for example, you wanted to execute the CLI routine cyclically or something like that; or if the program expected to operate on an input from stdin.
content_copyCOPY
https://softwareengineering.stackexchange.com/questions/204225/what-are-some-standard-design-methods-to-add-gui-to-a-command-line-app
Comments