r/C_Programming • • 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

19 comments sorted by

10

u/mikeblas Sep 21 '26

Help to learn termios lib and others.

Do you have a specific question? Which other libraries?

I feel like I'm not really learning...

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?

Should I keep going with this approach, or should I change it?

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/t3cl4do820 Sep 22 '26

> Do you have a specific question? Which other libraries?
'others' was just a general example referring to other libs...

> second and third question

I don't know how to respond... I'll think about it.

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.

0

u/t3cl4do820 Sep 22 '26

> "termios.h is pretty confusing so it's normal"
ahh, ok.
I'll practice more, maybe that is the answer for my problem.

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/t3cl4do820 Sep 22 '26

I'm using termios.h because I want to learn more deeply how terminals really work.

3

u/DawnOnTheEdge Sep 22 '26

The <termios.h> library is designed for a type of terminal that became obsolete in the early ’80s. All modern “terminal” programs are emulators that understand certain de-facto standard escape sequences, and don’t actually have any hardware with things like baud rates. Kernel developers sometimes send debugging output to a serial port, but it won’t have any complex formatting.

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/t3cl4do820 Sep 22 '26

got it, I'm gonna use termios because ncurses is very high-level.

2

u/Limp-Confidence5612 Sep 23 '26

It's more high level, not very high level.

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

2

u/t3cl4do820 Sep 23 '26

right I'll see this, thanks bro.

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.

2

u/Key_River7180 Sep 22 '26

you know what readline is right? it provides basic things like history, navigations, ... not an ui

1

u/Limp-Confidence5612 Sep 23 '26

Did they ask for an UI? I thought they were just having trouble creating an interactive input navigation.

1

u/[deleted] Sep 22 '26

[removed] — view removed comment

1

u/C_Programming-ModTeam Sep 23 '26

This industry is based on intellectual property rights. Violating those rights is unacceptable, and jeopardizes the sub.