Thread overview
Windows Console and writing Unicode characters
Mar 29, 2021
Brad
Mar 29, 2021
Adam D. Ruppe
Mar 29, 2021
Brad
Mar 30, 2021
Luhrel
Mar 30, 2021
Vinod K Chandran
Mar 30, 2021
Adam D. Ruppe
Mar 30, 2021
Luhrel
March 29, 2021
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
March 29, 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
March 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:
>> [...]
>
> 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

Perfect.  Thank you Adam.
March 30, 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("çéäö");
}
```
March 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.

March 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.
March 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:
>> 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.

Oh okay, I never had those issues, strangely enough.

It's a good website BTW.