Bryan
Bryan

Reputation: 339

How to print smiley face in Tcl

I have a smiley face pattern in plain text saved as a file called smile.txt

How do I print this file's content on my tool's console/terminal?

The goal was to print a smiley face when my code is successfully executed. Instead of writing puts "XXX" line by line I thought it might be easier this way.

Upvotes: 1

Views: 188

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137587

This is a known bug in the handling of Unicode characters outside the Basic Multilingual Plane (i.e., greater than U+00FFFF). We hope to have it fixed in 8.7; it is being actively worked on.

Workaround

As a workaround, this works for me but it might not work for you:

set t [fconfigure stdout -encoding]
fconfigure stdout -encoding iso8859-1
puts "\xF0\x9F\x98\x89"
fconfigure stdout -encoding $t

That's the sequence of bytes required in UTF-8, so flipping the encoding to ISO 8859-1 temporarily (that encoding is special as it “just writes the bytes” if you can generate them) lets you generate the sequence you need.

Upvotes: 3

Related Questions