Search code examples
adagnat

Ada: can I have two different console windows?


I'm using GNAT 2014 for an Ada project and I have a simple (I hope) question. Can I have two "consoles" open at the same time?

Let me explain why: my program outputs a lot of logging data to the console. What I would like would be to have two separate consoles, one that prints the program output and one that takes user inputs.

Is this doable? Or is this something that runs on the OS side of things, and Ada has no control over? I could achieve what I want with GtkAda, but since I'd like to use as little 3rd party libraries as possible I wanted to know if there was a native way first (also considering that the commands I need to issue are very basic, like "quit" or "pause", a console input would suffice).


Solution

  • You could for instance use GNATCOLL.Traces for the logging framework (instead of, I assume, Put_Line). This will allow you to control precisely where the logs should go, and in particular some of the logs can be configured to be sent to a file, some to the terminal.

    One thing you could do is send some of the logs to a file, and in your second terminal monitor that log file. This is also more convenient since it allows you to scroll up in the logs, whereas a terminal will tend to lose the older logs.

    Of course, the same approach can be done with a simple Put_Line (Standard_Error, "...") or even to a file, but GNATCOLL.Traces is configurable dynamically which is often more convenient.