linux ncurses

Started by
7 comments, last by alvaro 11 years, 5 months ago
what is underneath ncurses?
what is the 'win32' eqivalent in linux?

i want to program at the OS level in linux

any help, thanks
Advertisement
>> what is underneath ncurses?
What is underneath is a rather complex library that handles hundreds of different raw terminal types.

>>what is the 'win32' eqivalent in linux?
The Unix world is fundamentally different from the Windows world. The Unix world revolves around networking, connections, terminals, and connectivity sessions. The Windows world generally revolves around a single graphical desktop per session.

There is ncurses for Windows if you are interested in providing the same text-based experience on the platform.

>> i want to program at the OS level in linux
The OS level -- the operating system level -- is the level for operating the hardware systems. Sure, you can do it. The kernel source and nearly every major driver source is available to you. What hardware do you want to operate? Or did you mean something else with that?
so the kernel has console fuctions like, setconsolecursorposition, etc?

i dont want to learn any libraries,wraps,etc, i want to be able to develop them.
I was originially learning win32, but it isnt open source
No, the Linux kernel does not have quite that kind of functionality.

Think more in terms of escape codes across serial connections and writing directly to video memory.

The kernel talks to hardware. It provides an abstraction so programmers don't need to know about every video card's memory layout or every TTY's escape codes, they can simply have a virtual terminal with a cursor position and text color and such.

If you are really interested in it, the source isn't too hard to find. Go to kernel.org and download the source tree.
There is a level somewhat between curses and the kernel which is occupied by termcap and terminfo if you want to implement your own curses like library without drilling all the way down to the kernel.
Please don't do this. You're about to get sucked into a disaster of tears and pain.

"i want to program at the OS level in linux"

No you don't. Really, really, really, you don't. The only people who do this are people who are working on the OS. Everyone else uses the abstraction layers so they don't go insane and they do actually get some work done.

ncurses is good enough for people who implement shells, terminal media players, rogue-likes, interactive fiction games, tetris clones and a hundred others. It means their software runs reliably on thousands of configurations. It has had decades of development and debugging work by hundreds if not thousands of people.

Why would you give up all that? Because you imagine a performance gain? Painting a 1000 character display? Every screen refresh perhaps? On modern machines which are quite capable of repainting million-pixel displays at 50 or 60hz?

Why is this place so full of people who want to spend their time re-implementing these sorts of layers? Is it really just misguided masochism? Why do people want to faff about doing things like this instead of writing actual games?

Why is this place so full of people who want to spend their time re-implementing these sorts of layers? Is it really just misguided masochism? Why do people want to faff about doing things like this instead of writing actual games?


I don't think it's masochism. It's a combination of being new (to programming) and being young. Quite a few of the people starting like that will get shell-shocked and give up programming. Others will learn when to pick their battles and not try to reinvent every wheel and tiny cock and gear in the future. Some will decide that they like the fiddly engineering bits more than the game programming and we get people to work with the fiddly engineering bits. It's win-win for everyone. Well, except for the people completely giving it up.

I think it's fair to give people warning what they are about to get into, but if they want to dive head-first into the water, I'm not going to stand in their way. I did so too when I was much younger. It makes you appreciate having a mature and well-tested library for a boring task that still needs to be done.

so the kernel has console fuctions like, setconsolecursorposition, etc?

The kernel does not support concepts like consoles or cursor positions, at least not directly.

The way it works in a POSIX system like Linux is a display (whether it's a physical terminal connected over an RS-232C serial port or a virtual terminal rendered on a video card, what Windows parlance calls a 'console') is represented by a special file called a 'device,' and more particularly a 'character special device.' You open the device, read from it, write to it, close it, and sometimes perform out-of-band control functions on it (the [font=courier new,courier,monospace]ioctl()[/font] system call).

The specifics of which device you use and what control codes you send vary from target device to target device (and OS to OS, but assuming you're using a recent Linux kernel, you're probably targeting a /dev/tty* device).

There are libraries ([font=courier new,courier,monospace]man termcap[/font]) that help hide some of the device-specific peculiarities. You can also read the source of the built-in TTY driver in the kernel itself if you want to do fun things with the 'system console'. Read the manual on [font=courier new,courier,monospace]ioctl()[/font] for some addition hints, and hardware manuals for the various hardware or emulated hardware of a terminal window.

Stephen M. Webb
Professional Free Software Developer

Bregma's post above is probably the most relevant. I wanted to add that, if you don't want to use ncurses, you can get some of its functionality by using ANSI escape codes.

This topic is closed to new replies.

Advertisement