I had a little bit of fun with figlets the past few days. I came to the conclusion that they could be useful in seperating sections in Rust code. Generally, I find navigating in Rust a bit more difficult than C++, might be because I am not used to it, or because definitions and declarations tend to be gobbled together, and also enums and structures are generally more complex in Rust and C++.

I realised though that figlets could be used as sections titles, like in the following snippet:


//  ___                   _   __  __
// |_ _|_ __  _ __  _   _| |_|  \/  | ___  ___ ___  __ _  __ _  ___
//  | || '_ \| '_ \| | | | __| |\/| |/ _ \/ __/ __|/ _` |/ _` |/ _ \
//  | || | | | |_) | |_| | |_| |  | |  __/\__ \__ \ (_| | (_| |  __/
// |___|_| |_| .__/ \__,_|\__|_|  |_|\___||___/___/\__,_|\__, |\___|
//           |_|                                         |___/

/// Input messages to the decision module
#[derive(Clone)]
pub enum InputMessage
{
  /// Request to take a decision on a CFP
  DecideCFPAcceptance
  {
    /// CFP
    cfp: delegation::CFP,
  },
  /// Queue the execution of a task
  QueueExecution
  {
    /// uuid of the task
    uuid: Vec<u8>,
  },
}

//   ___        _               _   __  __
//  / _ \ _   _| |_ _ __  _   _| |_|  \/  | ___  ___ ___  __ _  __ _  ___
// | | | | | | | __| '_ \| | | | __| |\/| |/ _ \/ __/ __|/ _` |/ _` |/ _ \
// | |_| | |_| | |_| |_) | |_| | |_| |  | |  __/\__ \__ \ (_| | (_| |  __/
//  \___/ \__,_|\__| .__/ \__,_|\__|_|  |_|\___||___/___/\__,_|\__, |\___|
//                 |_|                                         |___/

/// Output messages of the decision module
#[derive(Clone)]
pub enum OutputMessage
{
  /// Proposal for a CFP
  CFPProposal
  {
    /// Proposal for a CFP
    proposal: delegation::Proposal,
  },
  /// Result of queuing the execution of a task
  QueueExecutionResult
  {
    /// uuid of the task
    uuid: Vec<u8>,
    /// True if the execution was accepted and queued
    accepted: bool,
  },
}

But then, I found it tedious to create those banners, by either using command line to generate a figlet or a website and then commenting the block. So I thought it could be fun to create a small command line tool to generate those banners for me. Simple enough, here came figlet-comment. Implemented in Rust, it originally used the figlet-rs library. Just for the fun of a pure rust solution.

And then it was just a matter of running the following command:

figlet-comment Some text!

To get a banner with comment, ready to insert in the code:

//  ____                                 _                   _     _ 
// / ___|    ___    _ __ ___     ___    | |_    ___  __  __ | |_  | |
// \___ \   / _ \  | '_ ` _ \   / _ \   | __|  / _ \ \ \/ / | __| | |
//  ___) | | (_) | | | | | | | |  __/   | |_  |  __/  >  <  | |_  |_|
// |____/   \___/  |_| |_| |_|  \___|    \__|  \___| /_/\_\  \__| (_)
//                                                                   

Unfortunatelly, as you can see, there are some spacing between the lettters. The figlet-rs library does not support kerning (or smooshing) :( I thought how hard can it be to support kerning?. It is actually relatively easy for figlets, it is well described in the FIGfonts specification.

It was a matter of:

  • computing the kerning
  • smooshing the characters together

The smooshing rules are well defined in the spec. To compute the kerning, it was a simple question of:

  • computing how many symbols to remove in the left and in the right character for every line.
  • selecting the smallest number of characters

For the smooshing, line-by-line,

The code for using figlets with kerning in pure rust can be found in the figleter crate.

And lead to the following output:

//  ____                         _            _   _ 
// / ___|  ___  _ __ ___   ___  | |_ _____  __ |_| |
// \___ \ / _ \| '_ ` _ \ / _ \ | __/ _ \ \/ / __| |
//  ___) | (_) | | | | | |  __/ | ||  __/>  <| |_|_|
// |____/ \___/|_| |_| |_|\___|  \__\___/_/\_\\__(_)
//                                                  

Updated: