digitalmars.D.learn - Windows Console and writing Unicode characters
- Brad (23/23) Mar 28 2021 I am new here so I will post this in Learn.
- Adam D. Ruppe (13/17) Mar 29 2021 You can still import std.stdio and use other functions with just
- Brad (2/18) Mar 29 2021 Perfect. Thank you Adam.
- Luhrel (12/21) Mar 30 2021 I have been used this trick in C++, so it might also work in D:
- Vinod K Chandran (2/13) Mar 30 2021 Works like a charm in Cmder. But it displayed some squares in CMD.
- Adam D. Ruppe (8/9) Mar 30 2021 If you follow through the link that's what I mention as being a
- Luhrel (3/13) Mar 30 2021 Oh okay, I never had those issues, strangely enough.
I am new here so I will post this in Learn. I have been doing a bit of reading on printing unicode characters in the Windows Console. Specifically W10 command prompt. I ran across a post by Adam Ruppe in a thread created a couple years ago which links a short bit of code and a quick discussion that Adam presents on his blog. Here is a link to the specific reply I refer to: https://forum.dlang.org/post/sjsqqhwvlonohvwyqihr forum.dlang.org Which points to his Blog post here: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_11_25.html#unicode The code snippet works great and does exactly what I want it to do. I am just curious - since it works by basically providing a custom implementation for writeln rather than use the one in stdout module (package?) that would mean any other functions from that package I would want to leverage I would need to include by name. Would it be acceptable then to maybe rename the custom writeln functions in my own code to something like uniwriteln and then include the standard library for other functions I might want to use? I am guessing this is not a problem, although I found the code a little intimidating and was not sure I wanted to play fast and lose with it... Thanks
Mar 28 2021
On Monday, 29 March 2021 at 02:12:57 UTC, Brad wrote:a custom implementation for writeln rather than use the one in stdout module (package?) that would mean any other functions from that package I would want to leverage I would need to include by name.You can still import std.stdio and use other functions with just the one overridden. D handles name lookups by just ... well, looking up lol. It starts in the current scope, then checks the next one up until the module, then starts looking at imported modules for the name. If there's two with the same name, it prefers the most local one, but you can override that by using the full name: import std.stdio; void writeln() {} writeln(); // since you have a local name, it uses that first getc(); // no local name, so it checks the imported modules std.stdio.writeln(); // specifically uses the one from the module
Mar 29 2021
On Monday, 29 March 2021 at 11:53:32 UTC, Adam D. Ruppe wrote:On Monday, 29 March 2021 at 02:12:57 UTC, Brad wrote:Perfect. Thank you Adam.[...]You can still import std.stdio and use other functions with just the one overridden. D handles name lookups by just ... well, looking up lol. It starts in the current scope, then checks the next one up until the module, then starts looking at imported modules for the name. If there's two with the same name, it prefers the most local one, but you can override that by using the full name: import std.stdio; void writeln() {} writeln(); // since you have a local name, it uses that first getc(); // no local name, so it checks the imported modules std.stdio.writeln(); // specifically uses the one from the module
Mar 29 2021
On Monday, 29 March 2021 at 02:12:57 UTC, Brad wrote:I am new here so I will post this in Learn. I have been doing a bit of reading on printing unicode characters in the Windows Console. Specifically W10 command prompt. I ran across a post by Adam Ruppe in a thread created a couple years ago which links a short bit of code and a quick discussion that Adam presents on his blog. Here is a link to the specific reply I refer to: https://forum.dlang.org/post/sjsqqhwvlonohvwyqihr forum.dlang.org [...]I have been used this trick in C++, so it might also work in D: ``` import core.stdc.stdlib; import std.stdio; void main() { version(Windows) system("chcp 65001 > NUL".ptr); writeln("çéäö"); } ```
Mar 30 2021
On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote:I have been used this trick in C++, so it might also work in D: ``` import core.stdc.stdlib; import std.stdio; void main() { version(Windows) system("chcp 65001 > NUL".ptr); writeln("çéäö"); } ```Works like a charm in Cmder. But it displayed some squares in CMD.
Mar 30 2021
On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote:I have been used this trick in C++, so it might also work in D:If you follow through the link that's what I mention as being a bad idea and provide the code given as a more correct alternative. It changes a global (well to the console) setting that persists after your program terminates, which can break other programs later, it can trigger font changes, and it doesn't actually always work anyway. You're much better off calling the correct functions.
Mar 30 2021
On Tuesday, 30 March 2021 at 13:19:02 UTC, Adam D. Ruppe wrote:On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote:Oh okay, I never had those issues, strangely enough. It's a good website BTW.I have been used this trick in C++, so it might also work in D:If you follow through the link that's what I mention as being a bad idea and provide the code given as a more correct alternative. It changes a global (well to the console) setting that persists after your program terminates, which can break other programs later, it can trigger font changes, and it doesn't actually always work anyway. You're much better off calling the correct functions.
Mar 30 2021