Skip to content

Commit

Permalink
[Ref] openmpt123: Move IsConsole and IsTerminal.
Browse files Browse the repository at this point in the history
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@21684 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed Sep 22, 2024
1 parent 12fbe5b commit 5ab2296
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
31 changes: 0 additions & 31 deletions openmpt123/openmpt123.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,37 +152,6 @@ struct show_long_version_number_exception : public std::exception {

constexpr auto libopenmpt_encoding = mpt::common_encoding::utf8;

#if MPT_OS_WINDOWS && !MPT_WINRT_BEFORE(MPT_WIN_10)
bool IsConsole( DWORD stdHandle ) {
HANDLE hStd = GetStdHandle( stdHandle );
if ( ( hStd != NULL ) && ( hStd != INVALID_HANDLE_VALUE ) ) {
DWORD mode = 0;
if ( GetConsoleMode( hStd, &mode ) != FALSE ) {
return true;
}
}
return false;
}
#endif // MPT_OS_WINDOWS && !MPT_WINRT_BEFORE(MPT_WIN_10)

bool IsTerminal( int fd ) {
#if MPT_OS_WINDOWS && !MPT_WINRT_BEFORE(MPT_WIN_10)
if ( !_isatty( fd ) ) {
return false;
}
DWORD stdHandle = 0;
if ( fd == 0 ) {
stdHandle = STD_INPUT_HANDLE;
} else if ( fd == 1 ) {
stdHandle = STD_OUTPUT_HANDLE;
} else if ( fd == 2 ) {
stdHandle = STD_ERROR_HANDLE;
}
return IsConsole( stdHandle );
#else
return isatty( fd ) ? true : false;
#endif
}

#if !MPT_OS_WINDOWS

Expand Down
31 changes: 29 additions & 2 deletions openmpt123/openmpt123.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,36 @@ struct field {


#if MPT_OS_WINDOWS && !MPT_WINRT_BEFORE(MPT_WIN_10)
bool IsConsole( DWORD stdHandle );
inline bool IsConsole( DWORD stdHandle ) {
HANDLE hStd = GetStdHandle( stdHandle );
if ( ( hStd != NULL ) && ( hStd != INVALID_HANDLE_VALUE ) ) {
DWORD mode = 0;
if ( GetConsoleMode( hStd, &mode ) != FALSE ) {
return true;
}
}
return false;
}
#endif // MPT_OS_WINDOWS && !MPT_WINRT_BEFORE(MPT_WIN_10)

inline bool IsTerminal( int fd ) {
#if MPT_OS_WINDOWS && !MPT_WINRT_BEFORE(MPT_WIN_10)
if ( !_isatty( fd ) ) {
return false;
}
DWORD stdHandle = 0;
if ( fd == 0 ) {
stdHandle = STD_INPUT_HANDLE;
} else if ( fd == 1 ) {
stdHandle = STD_OUTPUT_HANDLE;
} else if ( fd == 2 ) {
stdHandle = STD_ERROR_HANDLE;
}
return IsConsole( stdHandle );
#else
return isatty( fd ) ? true : false;
#endif
bool IsTerminal( int fd );
}


class textout : public string_concat_stream<mpt::ustring> {
Expand Down

0 comments on commit 5ab2296

Please sign in to comment.