Changeset 890 for cpp/common


Ignore:
Timestamp:
07/22/19 17:10:35 (5 years ago)
Author:
Maciej Komosinski
Message:

Added guiSetConsoleUTF8(); (mostly for Windows where it is not the default...)

Location:
cpp/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/console.cpp

    r400 r890  
    11#include "console.h"
    22#ifdef _WIN32
    3 
    43#include <windows.h>
    54#include "Convert.h"
     5#endif
    66
    7 #else
    8 
     7#if defined(LINUX) || defined(MACOS)
    98#include <stdio.h>
    109#include <termios.h>
     
    1211bool guiStdoutIsConsole()
    1312{
    14         static int in=-1;
    15         if (in<0)
     13        static int in = -1;
     14        if (in < 0)
    1615        {
    1716                struct termios t;
    18                 in=(tcgetattr(1,&t)==0);
     17                in = (tcgetattr(1, &t) == 0);
    1918        }
    2019        return in;
    2120}
    2221#endif
    23 
    2422
    2523void guiSetConsoleTitle(const char* utf8title) //platform-dependent implementations
     
    2826        SetConsoleTitleW(Convert::utf8ToUtf16(utf8title).c_str());
    2927#else
     28#if defined(LINUX) || defined(MACOS)
    3029        if (guiStdoutIsConsole())
    3130        {
    32                 printf("\033]0;%s\007",utf8title);
     31                printf("\033]0;%s\007", utf8title);
    3332                fflush(stdout);
    3433        }
     34#endif
    3535#endif
    3636}
    3737
    3838ConsoleColorMode console_color_mode = ConsoleColorNone;
     39
     40void 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}
  • cpp/common/console.h

    r399 r890  
    11#ifndef _CONSOLE_H_
    22#define _CONSOLE_H_
     3
    34#ifndef _WIN32
    45bool guiStdoutIsConsole();
     
    78enum ConsoleColorMode { ConsoleColorNone, ConsoleColorANSIDefault };
    89extern ConsoleColorMode console_color_mode;
     10void guiSetConsoleUTF8();
     11
    912#endif
Note: See TracChangeset for help on using the changeset viewer.