On Wed, Jun 11, 2014 at 04:28:08PM +0200, Stefano Zacchiroli wrote:
> However, implementing the above in ledger would require either
> launching tput an external command (which is not particularly nice) or
> linking to ncurses.

Or not :)

Plain old ioctl can actually query terminal width without requiring any
additional library --- example attached.

I think it would be a much more useful default for --columns than
getenv(COLUMNS), as the latter is almost always gonna be empty.

HTH,
Cheers.
-- 
Stefano Zacchiroli  . . . . . . .  [email protected] . . . . o . . . o . o
Maître de conférences . . . . . http://upsilon.cc/zack . . . o . . . o o
Former Debian Project Leader  . . @zack on identi.ca . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>

int main(void) {
	struct winsize ws;

	if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) {
		perror("can't query terminal size");
		exit(EXIT_FAILURE);
	}

	printf("columns=%d\n", ws.ws_col);

	exit(EXIT_SUCCESS);
}

Reply via email to