Hey, I've built a toy hex file reader on the terminal, however it's using always 80 cols because I haven't found a way to get terminal width in c in linux... please someone help me (just tell me some function or library, I looked on termios' man page but found no useful info)
I don't know the answer.
It sounds like you're going to reinvent the wheel though. May I suggest using ncurses? Handling terminals manually is hell; don't go there.
It's in the environment variable COLUMNS, read that out with whatever your language provides for that.
>>4
When you're doing terminal handling, using ncurses will eventually pay off. Generally when the alternative would turn out to be having a minor nervous breakdown.
Also, it's good practice which I'm assuming you're after here anyway (given that xxd piped to less or whatever generally does the trick as far as viewing is concerned). Ncurses doesn't exactly have the most obvious API around.
Anyway... you can't actually rely on the COLUMNS variable existing. Oh god, terminals in Unix-workalikes... just implementing your own terminal emulator is an exercise in bonking yourself in a very uncomfortable place.
>>2,5
You guys sound like Linux programmers. :( Come on, not every Unix is that bad, and not every programmer is as confused and despairing as you.
(I'll just preemptively add that I'm wrong, so nobody feels a need to argue with or respond to this.)
>>1
once you've got it detecting the width, what are you going to do when your output is to a pipe or file redirection?
if it's interactive, use ncurses; if it's not, just pick a line with that makes sense and let other more suitable utils handle paging and wrapping if the user desires it.
pick a line width, too
>>6
Yeah. For some reason, outputting terminal control codes directly from an application (i.e. not through some library) is considered dirty by younger Unix types. IMO this has nothing to do with Linux though; xterm is xterm regardless of particulars.
I guess most of us took a look at what's inside termcap and lost a few points of sanity to the ghosts of perverse old VT100 variant terminals that perhaps someone was still using in the mid-eighties.
> I guess most of us took a look at what's inside termcap and lost a few points of sanity to the ghosts of perverse old VT100 variant terminals that perhaps someone was still using in the mid-eighties.
hehe :)