Showing only posts with topic "releases" [.rss for this topic]. See all posts.

Calculating string display width in Ruby

Most programmers are by now familiar with the difference between the number of bytes in a string and the number of characters. Depending on the string’s encoding, the relationship between these two measures can be either trivially computable or complicated and compute-heavy.

With the advent of Ruby 1.9, the Ruby world at last has this distinction formally encoded at the language level: String#bytesize is the number of bytes in the string, and String#length and String#size the number of characters.

But when you’re writing console applications, there’s a third measure you have to worry about: the width of the string on the display. ASCII characters take up one column when displayed on screen, but super-ASCII characters, such as Chinese, Japanese and Korean characters, can take up multiple columns. This display width is not trivially computable from the byte size of the character.

Finding the display width of a string is critical to any kind of console application that cares about the width of the screen, i.e. is not simply printing stuff and letting the terminal wrap. Personally, I’ve been needing it forever:

  1. Trollop needs it because it tries to format the help screen nicely.
  2. Sup needs it in a million places because it is a full-fledged console application and people use it for reading mail in all sorts of funny languages.

The actual mechanics of how to compute string width make for an interesting lesson in UNIX archaeology, but suffice it to say that I’ve travelled the path for you, with help from Tanaka Akira of pp fame, and I am happy to announce the release of the Ruby console gem.

The console gem currently provides these two methods:

  • Console.display_width: calculates the display width of a string
  • Console.display_slice: returns a substring according to display offset and display width parameters.

There is one horrible caveat outstanding, which is that I haven’t managed to get it to work on Ruby 1.8. Patches to this effect are most welcome, as are, of course, comments and suggestions.

Try it out!.

Trollop 1.16.2 released

Trollop 1.16.2 has been out for a while now, but I realized I (heavens!) haven’t yet blogged about it.

Exciting features include:

  1. Scientific notation is now supported for floating-point arguments, thanks to Will Fitzgerald.
  2. Hoe dependency dropped. Finally.
  3. Some refactoring of the standard exception-handling logic, making it easier to customize Trollop’s behavior. For example, check this out:

opts = Trollop::with_standard_exception_handling p do
  p.parse ARGV
  raise Trollop::HelpNeeded if ARGV.empty? # show help screen

This example shows the help screen if there are no arguments. Previous to 1.16, this was difficult to do, since the standard exception-handling was baked into Trollop::options. The help message would automatically be displayed if -h was given, but programmatically invoking it on demand was difficult.

So I’ve refactored the standard exception handling into with_standard_exception_handling, and if you want fine-grained control, instead of calling Trollop::options, you now have the option to call Trollop#parse from within with_standard_exception_handling.

You don’t really need any of this stuff, of course, unless you’re really picky about how your exception-handling works. But hey, that’s why I wrote Trollop in the first place….

Trollop 1.15 released

I’ve just released Trollop 1.15, which fixes an irritating misfeature pointed out by Rafael Sevilla: when Trollop runs out of characters when it’s generating short option names, e.g. when you have a lot of options, it shouldn’t throw an exception and die. It should just continue peacefully.

Trollop’s reign of domination continues!

git wtf bf06ab7 released

I’ve released git-wtf version bf06ab7. The highlight of this release is colorized output. ANSI escape sequences are the future of the web.

Also, the feature / integration branch comparisons is now only displayed when -r is supplied.

Check out the git-wtf home page for an example of the fancy colorization, or just download it now.

Ritex 0.3 released

I’ve released Ritex 0.3. No API or functionality changes; this is just a set of miscellaneous tweaks that make Ritex work on Ruby 1.9.

Whisper 0.5 released

I’ve released Whisper version 0.5. Lots of good stuff since 0.3 (I didn’t announce 0.4 because it was a minor bugfix release):

  • Nested comments are now properly supported.
  • New <pre> and <poem> blocks added.
  • A new whisper-process-email command for manually reprocessing email. You can also offload all email processing to this program instead of the main Whisper server, if you like.
  • New dependency for the 0.2 version of RiTeX, which has equation array support (see announcement for details).
  • Better mbox-splitting code, now that I’ve figured out how to do this properly in Sup.
  • RiTeX macros now properly persist throughout an entry.
  • Many other minor bugfixes: attribution lines in emails, various incorrect bits of HTML output, escaping of Ritex error messages, etc.

Try it now!

  1. sudo gem install whisper --source
  2. whisper-init <blog directory>
  3. Follow the instructions.

git-wtf 58b87fe9 released

I’ve released version 58b87fe9 of git-wtf, available here:

This version contains a fairly major change: branches on origin are treated as equal to local branches, and branches that are remote-only are denoted with { }. So now there are three possible symbols: ( ) for local-only, { } for remote-only, and [ ] for branches that appear on both origin and your local repo.

The motivation was dealing with the fact that Sup has very many feature branches going at once, but I work on it on several different computers and typically only have a subset of them checked out. I didn’t want anyone to be left out….

I also fixed a few minor things like removing the restriction that version branches be local branches.

Ritex 0.2 released

It’s been almost four years since the previous release, so I’m happy to announce that Ritex 0.2 has been released today. This version features many bugfixes an improvements, most notably:

  • Array options are now supported. (Necessary to get the eqnarray-style equation alignment in this post.)
  • Unary minus heuristics are much improved.

Here’s a quick demo of the unary minus:


Sadly, just as with LaTeX itself, there are still times where you have to hint to get the right behavior:


Over the years since the last release it looks like there are two new options for generating MathML in Ruby. Itex2MML has developed Ruby bindings, and there’s some other project just called MathML. The big win for Ritex over these packages, of course, is macro support:

\define{\onion}{\hat{\theta}} -
\define{\potato}[1]{E_\theta[#1]} -

A quick gem install ritex should get it for you, and you can see some more example input/output pairs here.

Sup 0.7 released

Sup 0.7 has been released.

You can read the announcement here

The big win in this release is that Ferret index corruption issues should now be fixed, thanks to an extensive programming of locking and thread-safety-adding.

The other nice change is that text entry will now scroll to the right upon overflow, thanks to some arcane Curses magic.

Trollop 1.13 released

I’ve released Trollop 1.13. This is a minor bugfix release. Arguments given with =’s and with spaces in the values are now parsed correctly. (E.g. --name="your mom".)

Get it with a quick gem install trollop.

0 1  next