CODE
while (1)
    {
        keycode = key_hook();
        if (keycode == SPACE || keycode == BKSPACE)
        {
            render_again = 1;
        }
        if (keycode == ESC)
            break;
        if (render_again)
        {
            render_again = 0;
            render(all);
        }
        dprintf(1, "");      //I have no idea why this prevents the program from freezing
    }
    int key_hook()
    {
     char buffer[4];
     read(0, buffer, 4);
     return (*(unsigned int *)buffer);
    }
Alright, so this piece of code handles redrawing of text on screen. Some rows of text are underlined or highlighted using termcaps (tputs(tgetstr("us, NULL")......). Everything prints fine but after the first redraw of the text the while apparently freezes unless a dprintf/printf is present. The key_hook function just reads 4 bytes from the stdin and converts them to an int.
When I last did work here, my version of key_hook had a loop of single byte reads. This was broken by an alarm of 1 second and logic to whether the data so far was a key prefix.
The alarm interrupted the read, and stopped freeze
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With