Last change
on this file since 1303 was
890,
checked in by Maciej Komosinski, 5 years ago
|
Added guiSetConsoleUTF8(); (mostly for Windows where it is not the default...)
|
-
Property svn:eol-style set to
native
|
File size:
1.5 KB
|
Rev | Line | |
---|
[399] | 1 | #include "console.h" |
---|
| 2 | #ifdef _WIN32 |
---|
| 3 | #include <windows.h> |
---|
| 4 | #include "Convert.h" |
---|
[890] | 5 | #endif |
---|
[399] | 6 | |
---|
[890] | 7 | #if defined(LINUX) || defined(MACOS) |
---|
[399] | 8 | #include <stdio.h> |
---|
| 9 | #include <termios.h> |
---|
| 10 | |
---|
| 11 | bool guiStdoutIsConsole() |
---|
| 12 | { |
---|
[890] | 13 | static int in = -1; |
---|
| 14 | if (in < 0) |
---|
[399] | 15 | { |
---|
| 16 | struct termios t; |
---|
[890] | 17 | in = (tcgetattr(1, &t) == 0); |
---|
[399] | 18 | } |
---|
| 19 | return in; |
---|
| 20 | } |
---|
| 21 | #endif |
---|
| 22 | |
---|
[400] | 23 | void guiSetConsoleTitle(const char* utf8title) //platform-dependent implementations |
---|
[399] | 24 | { |
---|
| 25 | #ifdef _WIN32 |
---|
| 26 | SetConsoleTitleW(Convert::utf8ToUtf16(utf8title).c_str()); |
---|
| 27 | #else |
---|
[890] | 28 | #if defined(LINUX) || defined(MACOS) |
---|
[399] | 29 | if (guiStdoutIsConsole()) |
---|
| 30 | { |
---|
[890] | 31 | printf("\033]0;%s\007", utf8title); |
---|
[399] | 32 | fflush(stdout); |
---|
| 33 | } |
---|
| 34 | #endif |
---|
[890] | 35 | #endif |
---|
[399] | 36 | } |
---|
| 37 | |
---|
| 38 | ConsoleColorMode console_color_mode = ConsoleColorNone; |
---|
[890] | 39 | |
---|
| 40 | void guiSetConsoleUTF8() |
---|
| 41 | { |
---|
| 42 | #ifdef _WIN32 |
---|
| 43 | SetConsoleOutputCP(CP_UTF8); |
---|
| 44 | // SetConsoleCP(CP_UTF8); //set input code page. |
---|
| 45 | // ^^ Z ta linia po wpisaniu gdziekolwiek polskiego znaczka, fgets() zwraca NULL co powoduje ze konsola sie zamyka. |
---|
| 46 | // Uzycie fgetws() nie wiadomo czemu od razu wychodzi (nie wczytujac nic z konsoli) zwracajac jakies losowe znaczki - zmiana w stdiofile.h ktora testowalem: char *Vgets(char *s, int size) { wchar_t tab[1000]; wchar_t *x = fgetws(tab, 1000, file); if (x == NULL) return NULL; strcpy(s, Convert::wstrTOstr(tab).c_str()); return s; } |
---|
| 47 | // ^^ Bez tej linijki polskie znaki sa kodowane 1-bajtowo jako jakas strona kodowa (pojawiaja sie w konsoli ale frams takie znaki ignoruje jesli sa poczatkiem polecenia?) |
---|
| 48 | // ogolnie wszyscy narzekaja na konsole win... https://alfps.wordpress.com/2011/11/22/unicode-part-1-windows-console-io-approaches/ |
---|
| 49 | #endif |
---|
| 50 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.