January 26, 2019
On Friday, 25 January 2019 at 15:05:50 UTC, John Chapman wrote:
> On Friday, 25 January 2019 at 14:23:15 UTC, FrankLike wrote:
>> I need to set the font by the code now, because I need to do the installer, can't let this installer set the properties on each computer?
>
> SetCurrentConsoleFontEx perhaps?
>
> https://docs.microsoft.com/en-us/windows/console/setcurrentconsolefontex

That's so much code than next code.

///////////////////////////////////////////////
extern(C) int setlocale(int,char*);

static this()
{
	import core.stdc.wchar_;
	import core.stdc.stdio;
	fwide(core.stdc.stdio.stdout,1);
	setlocale(0,cast(char*)"china");
}
///////////////////////////////////
But After D2.078.1,it's not work.
Why?
Thank you.
January 26, 2019
On Saturday, 26 January 2019 at 06:03:25 UTC, FrankLike wrote:
> On Friday, 25 January 2019 at 15:05:50 UTC, John Chapman wrote:
>> On Friday, 25 January 2019 at 14:23:15 UTC, FrankLike wrote:
>>> I need to set the font by the code now, because I need to do the installer, can't let this installer set the properties on each computer?
>>
>> SetCurrentConsoleFontEx perhaps?
>>
>> https://docs.microsoft.com/en-us/windows/console/setcurrentconsolefontex
>
> That's so much code than next code.
>
> ///////////////////////////////////////////////
> extern(C) int setlocale(int,char*);
>
> static this()
> {
> 	import core.stdc.wchar_;
> 	import core.stdc.stdio;
> 	fwide(core.stdc.stdio.stdout,1);
> 	setlocale(0,cast(char*)"china");
> }
> ///////////////////////////////////
> But After D2.078.1,it's not work.
> Why?
> Thank you.

What has that code got to do with setting the console's font? So you need to add more code to accomplish that.
January 27, 2019
On Saturday, 26 January 2019 at 09:33:33 UTC, John Chapman wrote:

> What has that code got to do with setting the console's font? So you need to add more code to accomplish that.

You don't need to set the font to achieve the goal, why not?
January 27, 2019
On Sunday, 27 January 2019 at 06:14:15 UTC, FrankLike wrote:
> On Saturday, 26 January 2019 at 09:33:33 UTC, John Chapman wrote:
>
>> What has that code got to do with setting the console's font? So you need to add more code to accomplish that.
>
> You don't need to set the font to achieve the goal, why not?

This should work:

const(char)[] toCodePage(const(char)[] s, uint codePage = 0) {
  import core.sys.windows.winnls, std.utf;

  foreach (char c; s) {
    if (c >= 0x80) {
      auto temp = s.toUTF16z();
      char[] result;
      if ((result.length = WideCharToMultiByte(codePage, 0, temp, -1, null, 0, null, null)) != 0)
        WideCharToMultiByte(codePage, 0, temp, -1, result.ptr, cast(int)result.length, null, null);
      return result;
    }
  }
  return s;
}

void main() {
  import core.sys.windows.wincon, std.stdio;

  SetConsoleOutputCP(936); // Simplified Chinese codepage
  writeln("字符".toCodePage(936));
}
January 27, 2019
On Sunday, 27 January 2019 at 10:44:04 UTC, John Chapman wrote:
> On Sunday, 27 January 2019 at 06:14:15 UTC, FrankLike wrote:
>> On Saturday, 26 January 2019 at 09:33:33 UTC, John Chapman wrote:

>>
>>> What has that code got to do with setting the console's font? So you need to add more code to accomplish that.
>>
>> You don't need to set the font to achieve the goal, why not?
>
> This should work:
>
> const(char)[] toCodePage(const(char)[] s, uint codePage = 0) {
>   import core.sys.windows.winnls, std.utf;
>
>   foreach (char c; s) {
>     if (c >= 0x80) {
>       auto temp = s.toUTF16z();
>       char[] result;
>       if ((result.length = WideCharToMultiByte(codePage, 0, temp, -1, null, 0, null, null)) != 0)
>         WideCharToMultiByte(codePage, 0, temp, -1, result.ptr, cast(int)result.length, null, null);
>       return result;
>     }
>   }
>   return s;
> }
>
> void main() {
>   import core.sys.windows.wincon, std.stdio;
>
>   SetConsoleOutputCP(936); // Simplified Chinese codepage
>   writeln("字符".toCodePage(936));
> }
Yes.
////////////////////////////////////////
extern(C) int setlocale(int,char*);

static this()
{
	import core.stdc.wchar_;
	import core.stdc.stdio;
	fwide(core.stdc.stdio.stdout,1);
	setlocale(0,cast(char*)"china");
}
///////////////////////////////////////////
it's simple than yours,and don't need convert every string,why not work after D2.0.78.1?

January 28, 2019
On Sunday, 27 January 2019 at 16:23:42 UTC, FrankLike wrote:
> On Sunday, 27 January 2019 at 10:44:04 UTC, John Chapman wrote:
>> On Sunday, 27 January 2019 at 06:14:15 UTC, FrankLike wrote:
>>> On Saturday, 26 January 2019 at 09:33:33 UTC, John Chapman wrote:
>
>>>
>>>> What has that code got to do with setting the console's font? So you need to add more code to accomplish that.
>>>
>>> You don't need to set the font to achieve the goal, why not?
>>
>> This should work:
>>
>> const(char)[] toCodePage(const(char)[] s, uint codePage = 0) {
>>   import core.sys.windows.winnls, std.utf;
>>
>>   foreach (char c; s) {
>>     if (c >= 0x80) {
>>       auto temp = s.toUTF16z();
>>       char[] result;
>>       if ((result.length = WideCharToMultiByte(codePage, 0, temp, -1, null, 0, null, null)) != 0)
>>         WideCharToMultiByte(codePage, 0, temp, -1, result.ptr, cast(int)result.length, null, null);
>>       return result;
>>     }
>>   }
>>   return s;
>> }
>>
>> void main() {
>>   import core.sys.windows.wincon, std.stdio;
>>
>>   SetConsoleOutputCP(936); // Simplified Chinese codepage
>>   writeln("字符".toCodePage(936));
>> }
> Yes.
> ////////////////////////////////////////
> extern(C) int setlocale(int,char*);
>
> static this()
> {
> 	import core.stdc.wchar_;
> 	import core.stdc.stdio;
> 	fwide(core.stdc.stdio.stdout,1);
> 	setlocale(0,cast(char*)"china");
> }
> ///////////////////////////////////////////
> it's simple than yours,and don't need convert every string,why not work after D2.0.78.1?

I've no idea, sorry. A quick scan of D's changelogs between those versions doesn't reveal anything relevant. But I wonder how your code ever worked - on Windows, calling setlocale with "china" returns null, which means it's not a valid locale, so did nothing.

This does the right thing:

  extern(C) int _cwprintf(const(wchar)*, ...);

  void main() {
    SetConsoleOutputCP(936);
    _cwprintf("字符\n");
  }
1 2
Next ›   Last »