Skip to content

Commit 4f080cc

Browse files
committed
Added a unicode example.
Note: Because there's no standard unicode locale, this depends on the user's locale. Consequently, this may not work for all users (likely people who don't have other unicode working correctly, either). Moreover, I cannot guarantee adequate glyph coverage for the charaters used; the current example string is mixed first-level Japanese and ASCII.
1 parent b7e81e6 commit 4f080cc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/hello_unicode.d

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/** hello_unicode.d
2+
*
3+
* This is a demonstration of Unicode output with ncurses in D.
4+
*
5+
* The functionality of this code is otherwise identical to hello_world.d
6+
*
7+
* Modified by: Wyatt
8+
*/
9+
import std.string: toStringz;
10+
import std.c.locale; // Need setlocale()
11+
import deimos.ncurses.ncurses;
12+
13+
void main()
14+
{
15+
setlocale(LC_CTYPE,""); // You need to set the empty locale to use upper-plane glyphs
16+
// This sets the locale based on local variables. On most Unix-
17+
// like systems, you can use the `locale` command to show the
18+
// current settings for your environment.
19+
20+
auto hello = toStringz("日本語からの「Hello World!」");
21+
22+
initscr(); //initialize the screen
23+
printw(hello); //prints the char[] hello to the screen
24+
refresh(); //actually does the writing to the physical screen
25+
getch(); //gets a single character from the screen.
26+
endwin(); //Routine to call before exiting, or leaving curses mode temporarily
27+
}

0 commit comments

Comments
 (0)