I am an absolute beginner and I hardly understand the problem that @Isofruit 
code has solved. Bui I believe to have a similar problem in the code that I 
post here below. My question is: how can I add to textArea the same text it is 
echoed on console in miohttpd on the line echo "responding on port 8080..."?
    
    
    import std/asynchttpserver
    import std/asyncdispatch
    import nigui
    var
        thread1: Thread[void]
        textarea:TextArea
    
    app.init()
    var window = newWindow("NiGui Example")
    var container = newLayoutContainer(Layout_Vertical)
    window.add(container)
    var button = newButton("Button 1")
    container.add(button)
    textArea = newTextArea()
    container.add(textArea)
    button.onClick = proc(event: ClickEvent) =
        textArea.addLine("Button 1 clicked...")
    
    proc contenitore ()  = {.gcsafe.}:
        proc miohttpd  {.async} =
            var server = newAsyncHttpServer()
            proc cb(req: Request) {.async.}  =
                let headers = {"Content-type": "text/plain; charset=utf-8"}
                await req.respond(Http200, "Hello World\n", 
headers.newHttpHeaders())
                echo "responding on port 8080..."
            server.listen(Port(8080))
            echo "listening on port 8080..."
            while true:
                if server.shouldAcceptRequest():
                    await server.acceptRequest(cb)
                else:
                    echo "await sleepAsync"
                    await sleepAsync(500)
        waitFor miohttpd()
    
    createThread(thread1, contenitore)
    
    window.show()
    app.run
    
    
    Run

Reply via email to