There is a great tutorial about writing text editors for Unix terminals, with raw input, syntax coloring etc., which uses only the standard C library and standard headers available on Unix-like systems:
https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode.html
This chapter of the tutorial explains how to switch the terminal input to raw mode and process it with standard IO functions from C (read() & stuff). Then you can handle things like cursor movement, scrolling, colours etc. by writing to the output with certain escape sequences of the VT100 terminal. You can find more in this tutorial, including the links to all the documentations required, and sample source codes. There's also a GitHub repository with all the samples from the tutorial, as well as the final product, which is based on the Kilo editor written by antirez.
As for reading the special keys, like the arrow keys, Home ,End, PgUp, PgDown etc., try outputting the raw characters you get from the input and just press the keys you want to see what codes they map to. For the arrow keys, for example, they usually map to the escape sequences <ESC>[A through <ESC>[D, where <ESC> is the special control character with ASCII code 27 decimal or 0x1B hexadecimal. Those are the VT100 terminal escape codes that instruct the terminal to move the cursor one character into one of these four directions. More on handling these keystrokes in the next chapter of the aforementioned tutorial:
https://viewsourcecode.org/snaptoken/kilo/03.rawInputAndOutput.html
new1.c_lflag &= echo ? ECHO : ~ECHOis this really working? I would think it should be more along the lines ofnew1.c_lflag = echo ? new1.c_lflag | ECHO : new1.c_lflag & ~ECHO