The code as provided wouldn't compile. I cleaned it up with my best guesses and thus was working with the following:
#include <curses.h>
#include <stdint.h>
#include <termios.h>
#include <unistd.h>
void ncurses_demo1()
{
int ch;
initscr(); /* Start curses mode */
raw(); /* Line buffering disabled */
keypad(stdscr, TRUE); /* We get F1, F2 etc.. */
noecho(); /* Don't echo() while we do getch */
printw("Type any character to see it in bold\n");
ch = getch(); /* If raw() hadn't been called
* we have to press enter before it
* gets to the program */
if(ch == KEY_F(1)) /* Without keypad enabled this will */
printw("F1 Key pressed");/* not get to us either */
/* Without noecho() some ugly escape
* charachters might have been printed
* on screen */
else
{ printw("The pressed key is ");
attron(A_BOLD);
printw("%c", ch);
attroff(A_BOLD);
}
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
}
void termios_get_curr(struct termios* p_termios)
{
int32_t res;
res = tcgetattr(STDIN_FILENO, p_termios);
}
void termios_set_curr(struct termios* p_termios)
{
int32_t res;
res = tcsetattr(STDIN_FILENO, TCSANOW, p_termios);
}
void termios_set_work(struct termios* p_termios)
{
int32_t res;
res = tcgetattr(STDIN_FILENO, p_termios);
p_termios->c_lflag &= ~ICANON;
p_termios->c_lflag &= ~ECHO;
p_termios->c_lflag &= ~ECHOE;
p_termios->c_lflag &= ~ECHOK;
p_termios->c_lflag &= ~ECHONL;
p_termios->c_lflag &= ~ECHOPRT;
p_termios->c_lflag &= ~ECHOKE;
p_termios->c_lflag &= ~ISIG;
p_termios->c_lflag &= ~ICRNL;
p_termios->c_cc[VMIN] = 1;
p_termios->c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, p_termios);
}
bool console_linea_get(
uint8_t host_linea[], uint32_t host_linea_size,
bool is_echo, uint8_t host_prompt[])
{
bool ans;
char ch;
struct termios prev_opts;
struct termios* p_prev_opts;
struct termios work_opts;
struct termios* p_work_opts;
int32_t arrow;
int32_t i;
p_prev_opts = &prev_opts;
p_work_opts = &work_opts;
termios_get_curr(p_prev_opts);
termios_set_work(p_work_opts);
printf("%s ", host_prompt);
fflush(stdout);
arrow = 0;
i = 0;
while (i < host_linea_size - 1)
{
ch = getchar();
i++;
switch (ch)
{}
}
termios_set_curr(p_prev_opts);
host_linea[i] = '\0';
return ans;
}
void termio_funny1()
{
bool ans;
char host_linea[40];
uint32_t host_linea_size;
bool is_echo;
char host_prompt[] = "#";
is_echo = true;
host_linea_size = sizeof(host_linea);
ans = console_linea_get(host_linea, host_linea_size, is_echo, host_prompt);
}
int main(int argc, char* argv[])
{
ncurses_demo1();
termio_funny1();
return 0;
}
I'm not entirely clear on your question but it looks like you expected the prompt to print after the screen cleared (endwin() is called) but before the getch() loop in console_linea_get(). printf(...) is essentially a call to fprintf(stdout, ...). Normally for all files, stdout included, block buffering is enabled. fprintf() will write to the buffer which will be flushed once enough characters have been written. Adding a call to fflush(stdout) after the printf forces it to be written before you start reading input. You can also disable the buffer on stdout all together with a call to setbuf(stdout, NULL).