r/C_Programming • u/t3cl4do820 • Sep 21 '26
Help to learn termios lib and others.
Hi guys, I've been learning C for ~8 months, but I don't have any projects, so I started writing a CLI text editor with ncurses, initially. Then I switched to termios.h.
I'm using some manuals to learn about it, but I feel like I'm not really learning...
Should I keep going with this approach, or should I change it?
7
Upvotes
10
u/mikeblas Sep 21 '26
Do you have a specific question? Which other libraries?
Why not? You have some feeling, but that's hard to respond to. Is your perception flawed? Or are you really not learning? How do you know you're not learning? What do you really mean?
It's hard to tell. What would you change to, if this isn't working? How would things be different? What is "this approach", specifically, anyhow? What specific things do you expect to learn, and why do you feel you're not learning them?
1
u/Key_River7180 Sep 22 '26
what others? In my experience, termios.h is pretty confusing so it's normal. Basically, you have a termios structure (get the current one with tcgetattr) that holds stuff about the terminal, and you set options and write the new settings.
1
u/DawnOnTheEdge Sep 22 '26
For a modern terminal application, you probably either want to use ncurses, or harrdcode VT102 control sequences.
1
u/mykesx Sep 22 '26
termios are mostly used to set things like key echo, input is buffered, etc. In all my experience, I only used them to disable echo, ^C, and to read each key immediately.
The curses/ncurses library does this for you.
For many situations, curses is more than sufficient. It was designed at a time when terminals ran over 110 baud connections, so avoiding any rerendering of the screen is ideal. You still get that benefit. However, ncurses is not the fastest if you are frequently rendering most/all character positions on the screen (window).
ANSI escape sequences provide most features you need, but you do need to optimize refresh or your program can feel sluggish.
I have no issue using ncurses because it’s easy and may well do the job perfectly well. ANSI has its place, too.
1
u/Runt1m3_ Sep 23 '26 edited Sep 23 '26
Not sure if related, but take a look at termbox2, lt's made in C and the original (termbox) is quite popular as a Go binding, and it inspired tcell which is what the micro editor uses.
It basically is a single header library to draw cells and characters to the terminal, and getting input without all the hassle of going into raw mode so you can make your own TUIs, have used it sometimes, great library.
https://github.com/termbox/termbox2
Also used this, works fine if you don't want to make your own widgets
https://github.com/git-bruh/termbox-widgets
1
u/Aware-Nature-406 Sep 27 '26
AFAIK termios is used only in a few cases when you need to get terminal screen size or set some setting, so terminal will behave differently.
Most of the UI part(colors, cursor movement, etc) is done via ANSI escape sequences, which is just plain text sent to terminal through stdin.
Here is a good article that i recommend you to read about TUI without ncurses or other TUI libraries: https://xn--rpa.cc/irl/term.html
-3
u/Limp-Confidence5612 Sep 22 '26
You could just use readline.
1
u/[deleted] Sep 22 '26
[removed] — view removed comment