Skip to content

Commit 698397c

Browse files
committed
OFStdIOStream: Add -[hasTerminal]
FossilOrigin-Name: d5eb0384c57e721eaf42d22e7fa08bff9d5473e7455285b7d2f46bc86fcc68e3
1 parent 3474a9a commit 698397c

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/OFStdIOStream.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ OF_SUBCLASSING_RESTRICTED
5353
bool _atEndOfStream;
5454
}
5555

56+
/*!
57+
* @brief Whether there is an underlying terminal.
58+
*/
59+
@property (readonly, nonatomic) bool hasTerminal;
60+
5661
/*!
5762
* @brief The number of columns, or -1 if there is no underlying terminal or
5863
* the number of columns could not be queried.

src/OFStdIOStream.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,15 @@ - (unsigned int)retainCount
386386
return OF_RETAIN_COUNT_MAX;
387387
}
388388

389+
- (bool)hasTerminal
390+
{
391+
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
392+
return isatty(_fd);
393+
#else
394+
return false;
395+
#endif
396+
}
397+
389398
- (int)columns
390399
{
391400
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS)

src/OFWin32ConsoleStdIOStream.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ - (size_t)lowlevelWriteBuffer: (const void *)buffer_
456456
return length;
457457
}
458458

459+
- (bool)hasTerminal
460+
{
461+
/*
462+
* We can never get here if there is no terminal, as the initializer
463+
* changes the class to OFStdIOStream in that case.
464+
*/
465+
return true;
466+
}
467+
459468
- (int)columns
460469
{
461470
CONSOLE_SCREEN_BUFFER_INFO csbi;

0 commit comments

Comments
 (0)