ObjFW  Check-in [d5eb0384c5]

Overview
Comment:OFStdIOStream: Add -[hasTerminal]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d5eb0384c57e721eaf42d22e7fa08bff9d5473e7455285b7d2f46bc86fcc68e3
User & Date: js on 2020-05-28 00:15:05
Other Links: manifest | tags
Context
2020-05-28
00:34
tests: Use simple output if we have no terminal check-in: ef5b11edae user: js tags: trunk
00:15
OFStdIOStream: Add -[hasTerminal] check-in: d5eb0384c5 user: js tags: trunk
2020-05-24
17:06
Update to Unicode 13.0 check-in: 9c2715aaaa user: js tags: trunk
Changes

Modified src/OFStdIOStream.h from [3560f827f2] to [4b738f8353].

49
50
51
52
53
54
55





56
57
58
59
60
61
62
#else
	BPTR _handle;
	bool _closable;
#endif
	bool _atEndOfStream;
}






/*!
 * @brief The number of columns, or -1 if there is no underlying terminal or
 *	  the number of columns could not be queried.
 */
@property (readonly, nonatomic) int columns;

/*!







>
>
>
>
>







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#else
	BPTR _handle;
	bool _closable;
#endif
	bool _atEndOfStream;
}

/*!
 * @brief Whether there is an underlying terminal.
 */
@property (readonly, nonatomic) bool hasTerminal;

/*!
 * @brief The number of columns, or -1 if there is no underlying terminal or
 *	  the number of columns could not be queried.
 */
@property (readonly, nonatomic) int columns;

/*!

Modified src/OFStdIOStream.m from [0a4af80293] to [26a72da19c].

381
382
383
384
385
386
387









388
389
390
391
392
393
394
{
}

- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}










- (int)columns
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS)
	struct winsize ws;

	if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)







>
>
>
>
>
>
>
>
>







381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
{
}

- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}

- (bool)hasTerminal
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
	return isatty(_fd);
#else
	return false;
#endif
}

- (int)columns
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS)
	struct winsize ws;

	if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)

Modified src/OFWin32ConsoleStdIOStream.m from [c0629570e4] to [959c780c29].

451
452
453
454
455
456
457









458
459
460
461
462
463
464
	/*
	 * We do not count in bytes when writing to the Win32 console. But
	 * since any incomplete write is an exception here anyway, we can just
	 * return length.
	 */
	return length;
}










- (int)columns
{
	CONSOLE_SCREEN_BUFFER_INFO csbi;

	if (!GetConsoleScreenBufferInfo(_handle, &csbi))
		return -1;







>
>
>
>
>
>
>
>
>







451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
	/*
	 * We do not count in bytes when writing to the Win32 console. But
	 * since any incomplete write is an exception here anyway, we can just
	 * return length.
	 */
	return length;
}

- (bool)hasTerminal
{
	/*
	 * We can never get here if there is no terminal, as the initializer
	 * changes the class to OFStdIOStream in that case.
	 */
	return true;
}

- (int)columns
{
	CONSOLE_SCREEN_BUFFER_INFO csbi;

	if (!GetConsoleScreenBufferInfo(_handle, &csbi))
		return -1;