How to always print the prompt on a new line and keep input

Viewed 38

as new data comes from a server my prompt disappears as it should but is there a way of me getting back characters i entered after the arrow and putting those in front of a newly printed arrow?

void *recv_server_buff(void *sockfd)
{
    int end = 0;
    char recvBuff[1025];
    // memset(recvBuff, '\0', sizeof(recvBuff));
    while ((end = read(* (int *) sockfd, recvBuff, sizeof(recvBuff) - 1)) > 0) {
        recvBuff[end] = '\0';
        printf("\33[2K\r");
        if(fputs(recvBuff, stdout) == EOF) {
            printf("\n Error : Fputs error");
        }
        printf("\n");
        system("echo -n \"-> \"");
        // fflush(stdout);
    }

}

here is the function responsible for printing text on the screen note that i purposefully delete everything on a line as data from server comes, because i dont want arrows in front of the incoming data. please comment if i have something unclear and i'll try my best to explain. i am trying to make a simple chat

0 Answers
Related