mirror of
https://github.com/mpv-player/mpv
synced 2024-12-25 00:02:13 +00:00
io/win32: move mp_attach_console to terminal-win.c
Why didn't I put it there from the start?
This commit is contained in:
parent
d5fce546a4
commit
26d6eb4a8a
22
osdep/io.c
22
osdep/io.c
@ -327,26 +327,4 @@ char *mp_getenv(const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_attach_console(void)
|
|
||||||
{
|
|
||||||
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
|
|
||||||
// We have been started by something with a console window.
|
|
||||||
// Redirect output streams to that console's low-level handles,
|
|
||||||
// so we can actually use WriteConsole later on.
|
|
||||||
|
|
||||||
int hConHandle;
|
|
||||||
intptr_t hStdio;
|
|
||||||
|
|
||||||
hStdio = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
|
|
||||||
hConHandle = _open_osfhandle(hStdio, _O_TEXT);
|
|
||||||
*stdout = *_fdopen(hConHandle, "w");
|
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
|
||||||
|
|
||||||
hStdio = (intptr_t)GetStdHandle(STD_ERROR_HANDLE);
|
|
||||||
hConHandle = _open_osfhandle(hStdio, _O_TEXT);
|
|
||||||
*stderr = *_fdopen(hConHandle, "w");
|
|
||||||
setvbuf(stderr, NULL, _IONBF, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
|
@ -77,7 +77,6 @@ struct dirent *mp_readdir(DIR *dir);
|
|||||||
int mp_closedir(DIR *dir);
|
int mp_closedir(DIR *dir);
|
||||||
int mp_mkdir(const char *path, int mode);
|
int mp_mkdir(const char *path, int mode);
|
||||||
char *mp_getenv(const char *name);
|
char *mp_getenv(const char *name);
|
||||||
void mp_attach_console(void);
|
|
||||||
|
|
||||||
// NOTE: stat is not overridden with mp_stat, because MinGW-w64 defines it as
|
// NOTE: stat is not overridden with mp_stat, because MinGW-w64 defines it as
|
||||||
// macro.
|
// macro.
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -238,6 +239,22 @@ void terminal_set_foreground_color(FILE *stream, int c)
|
|||||||
|
|
||||||
int terminal_init(void)
|
int terminal_init(void)
|
||||||
{
|
{
|
||||||
|
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
|
||||||
|
// We have been started by something with a console window.
|
||||||
|
// Redirect output streams to that console's low-level handles,
|
||||||
|
// so we can actually use WriteConsole later on.
|
||||||
|
|
||||||
|
int hConHandle;
|
||||||
|
|
||||||
|
hConHandle = _open_osfhandle((intptr_t)hSTDOUT, _O_TEXT);
|
||||||
|
*stdout = *_fdopen(hConHandle, "w");
|
||||||
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
|
|
||||||
|
hConHandle = _open_osfhandle((intptr_t)hSTDERR, _O_TEXT);
|
||||||
|
*stderr = *_fdopen(hConHandle, "w");
|
||||||
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
CONSOLE_SCREEN_BUFFER_INFO cinfo;
|
CONSOLE_SCREEN_BUFFER_INFO cinfo;
|
||||||
DWORD cmode = 0;
|
DWORD cmode = 0;
|
||||||
GetConsoleMode(hSTDOUT, &cmode);
|
GetConsoleMode(hSTDOUT, &cmode);
|
||||||
|
@ -249,7 +249,6 @@ static void osdep_preinit(int *p_argc, char ***p_argv)
|
|||||||
talloc_enable_leak_report();
|
talloc_enable_leak_report();
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
mp_attach_console();
|
|
||||||
mp_get_converted_argv(p_argc, p_argv);
|
mp_get_converted_argv(p_argc, p_argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user