adoxa / ansicon

Process ANSI escape sequences for Windows console programs.
http://ansicon.adoxa.vze.com/
Other
1.23k stars 130 forks source link

After installing ANSICON when I run Cucumber I see special characters #98

Open JuanBer opened 8 years ago

JuanBer commented 8 years ago

Hi,

I started working with Ruby + Cucumber on my windows 10 Home x64. When I run a feature (UTF-8 encoded) without installing ansicon I see characters like 'ñ' or accent marks (since I'm writing my features in spanish) in the right way.

But when I install ansicon (I used versions 1.60 and 1.66) those characters are modified and I see symbols and special characters that replace them.

I don't know what to do and it's very annoying to see the output with those characters,

Is something I can do to fix it?

Let me know if I should add more info to this bug, I'm new doing this.

Version of Ruby I installed: https://s3.amazonaws.com/railsinstaller/Windows/railsinstaller-3.2.0.exe Version of ansicon I used: v1.60 o v1.66 for x64. CMD active page code: 850.

See following images (the only thing I changed between one and the other is that I installed ansicon v.1.66, with the older versions is the same)

withoutansicon

withansicon_v166

Thanks! Juan.

adoxa commented 8 years ago

This looks to be related to #91. You may be able to do chcp 65001 and have it work. Alternatively, you may not even need ANSICON at all (Windows 10.0.10586 supports sequences itself, see #94) - try set ANSICON=1 to fake out Ruby (although you may need the proper dimensions) and see if that works.

Memerto commented 7 years ago

I agree with OP. When i use an old version thats inside this gem => https://github.com/titusfortner/webdrivers I get this warning: image

But with this new version i get: image

It doesn't change a thing the chcp 65001 command.

adoxa commented 7 years ago

I just don't know what I'm doing with Rails/Cucumber, can you give me something to test?

Memerto commented 7 years ago

Just like OP, i don't use Rails, only Cucumber + Ruby plus Watir. And every time i run any scenario (in spanish) i get the same thing.

If i run those scenarios in a PowerShell, then i get the same result.

The way for you to replicate it is by making an Scenario in Spanish with this:

Característica: Test

You should not see the ' í ' if you have the ansicon in the PATH, and if you change the folders name and open another terminal, you should see it.

Don't know who i can help you with this

PD: Keep in mind that when i use the --output of cucumber and dump it into a file, the special characters in that file appear without problem.

adoxa commented 7 years ago

I know nothing about Ruby, Cucumber or Watir, so telling me to "make a Scenario" doesn't help any. Can you give me some precise steps?

Memerto commented 7 years ago

Install Ruby on your system (Search on Google for your OS since there are many). Then on a terminal (or a cmd with Ruby on Windows) Run these comands:

gem install cucumber gem install watir

After those are installed, on the terminal go to a new folder (lets call it TEST) and run:

cucumber --init

This will make the base of 3 folders:

-features --step_definitions --support

On the feature folder, create a .feature file and in it put this on the beginning:

language: es

Característica: First Try

If you remove the first line, it will work in English. Now in this file you create your Scenario with sentences using some reserved words like When,Then,etc. But since we are doing the test in Spanish, add this simple scenario

language:es

Característica: First Try

Escenario: Go to Google Dado que ingreso a la pagina de Google Entonces deberia ver "Google"

Now go to the "step_definitions" folder and create a .rb file in which add this to the file:

language: es

require "watir"

Dado (/^que ingreso a la pagina de Google$/) do @browser.goto "http://www.google.com" end

Entonces (/^deberia ver "([^"]*)"$/) do |text| @browser.text.include? text end

Finally go to the "env.rb" file thats inside the "support" folder and add this:

Before do @browser = Watir::Browser.new :firefox end

You can try with others web browsers but you need to download the web driver for those, Firefox is included so there is no need to download something.

Now for the test, go to a terminal with Ruby and go to the TEST folder and run: cucumber

This will run all the Scenarios that there are.For now is ok since there is only one.

If you run the test with the Ansicon on the PATH and then again but without the Ansicon on the PATH, you should get what we get.

adoxa commented 7 years ago

Thanks! Here's what I get (Win7, but I expect Win10 to be the same).

cucumber

So I can confirm the bug, but looks like Cucumber at least works without ANSICON, just set ANSICON=1 to pretend it's present.

adoxa commented 7 years ago

From what I can gather, Ruby has parsed escapes itself since June 2012, but apparently Cucumber isn't aware of that. Without ANSICON Ruby is writing directly to the console, so UTF-8 is preserved (via WriteConsoleW), but when ANSICON is present it switches to byte-by-byte WriteFile, losing the UTF-8 characters. I thought I fixed that in an as yet unreleased version, but it crashes, so there's still more to be done. Maybe now I'll finally take the time...

Memerto commented 7 years ago

Nice that you made it. Thats very interesting, take your time ;)

PD: When i do set ANSICON=1still appear with broken characters. I'm using Windows 10

adoxa commented 7 years ago

Is that with ANSICON still running? The set is only to remove Cucumber's warning, it's Ruby itself processing the escapes, so ANSICON is not needed at all. Looking further, I don't think I can fix this in ANSICON, as Ruby is translating the characters before ANSICON gets them, so if you need ANSICON running for other stuff, you'll have to exclude your version of Ruby's msvcrt, e.g.: set ANSICON_EXC=msvcrt-ruby220.dll (look in Ruby's bin directory for the actual version).

Memerto commented 7 years ago

I don't think I can fix this in ANSICON, as Ruby is translating the characters before ANSICON gets them

Ok if your sure is not an ANSICON problem then close this issue as resolved ;)

Keep in mind both of us have windows 10

adoxa commented 7 years ago

Here's what I see in 10 (same versions of Ruby and ANSICON).

ruby

Memerto commented 7 years ago

I did many test and i made it work in a PowerShell. It need to have the DevKit of ruby in the PATH. But still a cmd+Ruby or cmd alone keeps getting the wrong characters.

The thing is, PowerShell have color by itself and maybe don't need ANSICON.

PS: The PowerShell doesn't have that many color so the output of the cucumber is all in the same color (without ANSICON). But when i add ANSICON to the PATH and run a PowerShell, then i get the same problem but with color.