This is probably a silly question, but alas, I'll ask it anyway...
Is it possible with Python, to change the font of the text returned in the Terminal Window in OS X? For example, lets say I'm running a Python program in Terminal, and it asks me "Please enter an English word to be changed to Greek:". So I then enter "bread". Is it possible for the next answer that Python returns in the Terminal Window to be displayed in the 'Symbols' font so that the Greek text is displayed correctly? I have my doubts, but thought I'd ask.
Re: changing fonts?
> Is it possible for the next answer that Python returns in the
> Terminal Window to be displayed in the 'Symbols' font so that the
> Greek text is displayed correctly?
I don't think you can control the font, but you can print
out the Greek text as utf8-encoded unicode. I just tried
an experiment and managed to get Greek letters displayed
I had to turn off the "Wide Glyphs for Japanese/Chinese etc."
option under File/Get Info to get the spacing to come out
Re: changing fonts?
I'm not *that* familiar with the Terminal program on OS/X, but regardless
perhaps I can point out a possibly useful path to explore...
With terminal programs generally -- especially more in the past, as then they
were much more about emulating "real" terminals -- a lot of the terminal
progam's behavior and configuration could be controlled with what are called
Escape sequences were named as such because, most often, these control
sequences were output from the computer to the terminal (often over a serial
port) and, crucially, started with the escape character (ASCII 27, also known
as Ctrl-]). This escape character signaled to the terminal that the output
arriving from the computer was not to be displayed, but rather flagged the
output as control information for the terminal itself, such as "switch to
boldface", "change the text color to blue", "move the cursor to position 11,
43", or "change your character set to Latin-1", etc.
(My apologies if you already know this stuff. It's necessary background,
though, so I figured better to include it just in case...)
So, hopefully you can see where I'm going with this. It's quite possible that
OS/X's Terminal window understands a certain escape sequence to instruct it
change the active font as well (since it's an Xterm emulator, I'm confident
that escape sequences are used to control typeface, cursor location, text
color, and many other things). If so, then having Python change the font is
simply a matter of having your Python program emit the correct escape sequence
at the time you desire the font to change. Note, however, that the font will
most likely change for the ENTIRE Terminal screen, all at once. Historically,
while many "real" terminals might have supported multiple fonts, very few
supported multiple fonts SIMULTANEOUSLY. Terminal emulators such as OS/X's
Terminal, being based on the "real" terminals of days past, generally behave
in the same way.
So, the good news is that this could be pretty easy to implement. The trick,
however, will be figuring out if such an escape sequence exists for Terminal,
and, if so, what it is. Google is your friend. Also, check out the termcap
and/or terminfo entries -- /etc/termcap and (probably)
/usr/share/terminfo/*/*, respectively -- for Terminal's TERM type. If such an
escape sequence exists, it might well already be documented in one or both of
these terminal databases.
The only other alternative that readily comes to mind is that perhaps there's
some programmatic interface to Terminal to tell it to change it's font. I
tend to doubt this, but if it does exist then it will likely involve IPC
(inter-process communication) and not be trival to implement (although not
outrageously hard, either) -- you'd have to establish a connection between
Python and the correct Terminal instance, and then send the right IPC message.
Also, I guess that perhaps Terminal might even accepts signals to change its
font (again, doubtful though). Check out Terminal's manual page (i.e., run
"man Terminal") and see what signals it accepts and what they do. If you find
one that changes the font, then just running something like "kill -SIGXXX
999999" might work (where SIGXXX is a real and valid signal name and 999999 is
a real and valid process number for the correct Terminal instance).
I hope this is helpful, at least in terms of the alternative you have before
you (as I see them): escape sequences, some sort of IPC, or system signals.
Again, I think you might get luckly with the first option, whereas I have
serious doubts that Terminal supports the latter two options (but ya never
P.S. -- I just realized that you probably need to switch Terminal's CHARACTER
SET, not it's FONT. That said, though, everything I wrote is still applicable
-- just replace "character set" wherever I talk about "font". Plus, I think
there's a MUCH higher probability that there exists escape sequences to switch
Terminal's active character set (as compared to switching its font). However,
you may run into the problem that -- as I described as a possibility
concerning fonts -- Terminal might not be able to display but one character
set at a time (i.e., it can only change the character set for the entire
window at once), which could be add odds with your requirements. If Terminal
can only have one active character set at a time, then IF there's a character
set it supports that has BOTH Greek and English characters, you'd still be
able to pull it off. A lot of the European character sets ARE like this
(i.e., English chars mixed with specific European chars) -- but not the Symbol
character set, I believe -- so I suspect that you're in good luck! Once you
can successfully switch character sets, it's probably then just a matter of
tooling around with different character sets to see which one works for your
needs. For this stuff, provided OS/X has it, the program tput will definitely
Be Your Friend. Run "man tput" (and/or Google "terminfo tput") to learn more.
On Fri, 7 Dec 2007 19:55:50 -0600, <email@example.com>
> This is probably a silly question, but alas, I'll ask it anyway...
> Is it possible with Python, to change the font of the text returned in the
> Terminal Window in OS X? For example, lets say I'm running a Python
> program in Terminal, and it asks me "Please enter an English word to be
> changed to Greek:". So I then enter "bread". Is it possible for the next
> answer that Python returns in the Terminal Window to be displayed in the
> 'Symbols' font so that the Greek text is displayed correctly? I have my
> doubts, but thought I'd ask.
|All times are GMT. The time now is 01:43 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.