digitalmars.D.learn - What is the alternative to the setlocale function of c in D? Thank
- FrankLike (22/22) Jan 23 2019 Hi,everyone,
- FrankLike (5/23) Jan 23 2019 In D2.078.1 It can display Chinese characters correctly!
- Kagamin (3/3) Jan 24 2019 Try workarounds here:
- FrankLike (12/15) Jan 24 2019 Ok,thank you.
- FrankLike (2/5) Jan 24 2019 How do I set the font? Please.
- Kagamin (2/2) Jan 25 2019 Create a shortcut to cmd.exe and edit its properties. The console
- FrankLike (6/8) Jan 25 2019 I known that.
- John Chapman (3/6) Jan 25 2019 SetCurrentConsoleFontEx perhaps?
- FrankLike (15/21) Jan 25 2019 That's so much code than next code.
- John Chapman (3/26) Jan 26 2019 What has that code got to do with setting the console's font? So
- FrankLike (2/4) Jan 26 2019 You don't need to set the font to achieve the goal, why not?
- John Chapman (22/27) Jan 27 2019 This should work:
- FrankLike (14/43) Jan 27 2019 Yes.
- John Chapman (11/59) Jan 28 2019 I've no idea, sorry. A quick scan of D's changelogs between those
- Kagamin (2/2) Jan 25 2019 also
- FrankLike (15/17) Jan 25 2019 That's so much code than next code!
Hi,everyone, for example: import std.stdio; import std.process:executeShell; 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"); } void main() { writeln("字符"); executeShell("pause"); } ///////////////////////code end///////////////////////////// In D2.078.1 It works very ok. But After D2.080 ,It not works. Who can help me? Thank you.
Jan 23 2019
On Thursday, 24 January 2019 at 07:48:44 UTC, FrankLike wrote:Hi,everyone, for example: import std.stdio; import std.process:executeShell; 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"); } void main() { writeln("字符"); executeShell("pause"); } ///////////////////////code end/////////////////////////////In D2.078.1 It can display Chinese characters correctly! But After D2.080 , but it can't be used now. Who can help me? Thank you.
Jan 23 2019
Try workarounds here: https://issues.dlang.org/show_bug.cgi?id=1448 https://issues.dlang.org/show_bug.cgi?id=2742
Jan 24 2019
On Thursday, 24 January 2019 at 12:19:44 UTC, Kagamin wrote:Try workarounds here: https://issues.dlang.org/show_bug.cgi?id=1448 https://issues.dlang.org/show_bug.cgi?id=2742Ok,thank you. import std.stdio; import core.sys.windows.windows; import std.process:executeShell; extern(Windows) bool SetConsoleOutputCP(uint); void main() { SetConsoleOutputCP(65001); writeln("字符"); executeShell("pause"); }
Jan 24 2019
On Thursday, 24 January 2019 at 12:19:44 UTC, Kagamin wrote:Try workarounds here: https://issues.dlang.org/show_bug.cgi?id=1448 https://issues.dlang.org/show_bug.cgi?id=2742How do I set the font? Please.
Jan 24 2019
Create a shortcut to cmd.exe and edit its properties. The console window itself has a system menu for this too.
Jan 25 2019
On Friday, 25 January 2019 at 08:41:23 UTC, Kagamin wrote:Create a shortcut to cmd.exe and edit its properties. The console window itself has a system menu for this too.I known that. 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? Thank you.
Jan 25 2019
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
Jan 25 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: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.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
Jan 25 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:What has that code got to do with setting the console's font? So you need to add more code to accomplish that.On Friday, 25 January 2019 at 14:23:15 UTC, FrankLike wrote: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.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
Jan 26 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?
Jan 26 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: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)); }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?
Jan 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: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?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)); }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?
Jan 27 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: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"); }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: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?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)); }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?
Jan 28 2019
also http://blogs.microsoft.co.il/pavely/2009/07/23/changing-console-fonts/
Jan 25 2019
On Friday, 25 January 2019 at 16:14:56 UTC, Kagamin wrote:also http://blogs.microsoft.co.il/pavely/2009/07/23/changing-console-fonts/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"); } ///////////////////////////////////////// After D2.078.1,it's not work. why? thank you.
Jan 25 2019