Ruby display unicode character - ruby

I'm trying to print out some Unicode characters:
# encoding: utf-8
puts "ử ậ ắ ặ ố ồ"
If I run it through Powershell, this is what I get:
If I run it through cmd, this is what I get:
If I run it in Eclipse (with Aptana Studio 3 plugin), this is what I get:
Is it a problem with my system/software or is it Ruby's problem? How can I get it to work?
It works on Ideone though: http://ideone.com/PdycKH

Ruby supports it no problem, and setting the formatting at the top of the file is the way to go.
The issue is the display via the command line window. You need to use both a font and character page that supports Unicode display.
See this question regarding doing this in the Windows command line.
About the chcp command

I figured it out:
For cmd and Powershell, I have to change the font (I changed to Consolas)
In Eclipse, I have to change the encoding: go to Run/Run configurations, select the Common tab, change the Encoding to Other: UTF-8

Related

Cannot cat shift-jis file in mac terminal

I have a file that emacs correctly displays on mac. When I cat or less the file in mac terminal I see garbled characters such as "?E?u?#?#?#?#?#?#?#?". Running chardetect indicates SHIFT-JIS.
I tried adding the following to ~./bashrc but still see the same output.
export LANG=ja_JP.SHIFT_JIS
export LC_ALL=ja_JP.SHIFT_JIS
Under encodings in preferences for terminal, all encodings are checked including the Japanese ones.
Am I missing some other method here for viewing these files? I can see other files with Japanese characters in the mac terminal.
You need to change the text encoding at the Advanced tab in profile preferences to make Terminal use different encoding.
Env vars (LANG, LC_ALL) only affect the shell and child processes.
Also note that some characters from Windows cannot be displayed (①,髙,Ⅰ (roman digit) etc).

IntelliJ IDEA Terminal Special Characters

I recently started using IntelliJ IDEA Ultimate on Windows 10 and would really like to use the integrated terminal.
However, I can't get it to work with special characters like german umlauts or something like §.
That wouldn't be a problem if i hadn't some folders starting with Ü which i can't rename because they are part of a version control repo.
Because of that, i can't cd into these folders.
For example, an "ü" keystroke shows as "3R" and a "§" keystroke shows as "?" (like most special chars).
It neither works with the default terminal setting (cmd.exe) nor with git bash.
Has someone encountered a similar problem / has a solution for that?
I have had similar issues with IntelliJ Ultimate on Windows 10, regarding language and encoding on the Git Bash integrated Terminal. It was solved by setting the environment variables for the integrated terminal with the correct language. It can be done as follows:
Go to Settings
Terminal
Environment variables
Set two variables: LC_ALL=YOUR_LANGUAGE.utf8;LANG="$LC_ALL", where YOUR_LANGUAGE is the language code for the desired language. I searched a little and I think the correct one for German Umlauts is: de_DE.utf8. So, the configuration line would be:
- LC_ALL=de_DE.utf8;LANG="$LC_ALL"
Maybe you can set the file encoding by adding
-Dfile.encoding=UTF-8
to the idea64.vmoptions configuration file.

How can I set my GHCi prompt to a lambda character on Windows?

I want to have a lambda (λ) symbol as my prompt in GHCi (7.8) on Windows 7, so I set up my .ghci file as
:set +m
:set prompt "λ: "
:set prompt2 " | "
And I set my console font to Lucida Console since it's supposed to support Unicode, but when I load up GHCi, it looks like this instead
How can I get Windows to recognize the λ symbol properly?
Using > chcp.com 65001 worked with GHCi but opening other text files with Vim after setting that encoding returned garbled text.
Add the following to your %USERPROFILE%\.ghci. Instead of changing the encoding, you can use the Unicode escaped lambda \x03BB:
:set prompt "\x03BB: "
If %USERPROFILE%\.ghci does not exist, create it first before making the change.
This is actually quite a simple fix, just run the following command before starting GHCi:
> chcp.com 65001
This sets Window's encoding to the 65001 code page, which lets the λ get displayed properly:
This will also let a lot of other Unicode characters be displayed properly in cmd.exe and other Windows shells (such as Cygwin bash), but Windows' Unicode support is still not perfect, and some fonts don't support many of the characters. Luckily, λ happens to be a supported character so we can all have the classic GHCi prompt.
Using Răzvan Flavius Panda's answer, I decided to make a configuration file that had three flags for setting the prompt. The reason for this is prompt-cont is for GHCi versions >= 8.2.0, whereas prompt2 is for older GHCi versions.
I had a look at a short tutorial about configuring GHCi to try and find out where to put the configuration file. The site says that GHCi reads configuration files in the following order:
./.ghci (Local configuration file.)
Depending on your OS:
*nix: $HOME/.ghc/ghci.conf
Windows: C:\Users\<name>\AppData\Roaming\ghc\ghci.conf
$HOME/.ghci (Possibly *nix only; didn't work for me.)
I chose the second option.
C:\Users\Edwin\AppData\Roaming\ghc\ghci.conf:
:set prompt "\x03BB> "
:set prompt2 "\x03BB| "
:set prompt-cont "\x03BB| "
Explanation:
\x03BB stands for λ.
prompt is the main prompt. So it'll be "λ> ".
prompt2 is for a secondary prompt (I haven't seen it yet). So it'll be "λ| ".
prompt-cont is the same as prompt2, and is a replacement for prompt2 in GHCi 8.2.0.

UTF-8 in Windows 7 CMD [duplicate]

This question already has answers here:
How to use unicode characters in Windows command line?
(19 answers)
Closed 6 years ago.
I've tried to display UTF-8 in the win7 cmd. Currently, I'm using the standard font because as I see with the mysql.exe, it works fine with the characters I'm working with (currently the german umlauts "ßäöüÄÖÜ"). Also, with another font, the same characters appear.
But the output of my PHP script displays garbage, e.g. 'ß' for 'ß'. When I pipe the output into a file and open it up with Notepad++, it says the encoding is UTF-8. In php.ini I set UTF-8 as the encoding as well as in the connection to the mySQL database, and in the database itself UTF-8, too.
In CMD I tried so far to set the code page to 65001, but nothing changes.
edit: my PHP script is saved as UTF-8 as well
It seems with latin1, my desired characters can be displayed too and actually it works. But there has to be a way to do it in UTF-8? I can't convert everything to latin1
This question has been already answered in Unicode characters in Windows command line - how?
You missed one step -> you need to use Lucida console fonts in addition to executing chcp 65001 from cmd console.

debugging is not working, but just running is fine on PyCharm 2.7

If I run the program, it outputs the results fine, but if I try to debug it, I get the following error:
...
# coding=utf-8
^
SyntaxError: invalid character in identifier
I have
# encoding=utf-8
on the first line. This is not a syntatic error, because even if I delete the first line, I get the same error message with  prepended to the new first line.
I have set the EOL to be LF and the encoding to be UTF-8. My PyCharm is updated to the latest version 129.782
I opened up gVim and removed those characters. For some reason it would not appear in PyCharm. I am almost certain that PyCharm put that there though. I cannot type those characters with my keyboard, and I do not work with such characters for my programs.

Resources