2016-05-19

bnr.js

As I mentioned already, I use node.js for scripting. The same scripts work on OsX, Linux and Windows. Also, its fast, stable enough and somehow interesting. Microsoft is investing into it too: new VS Code editor is written on node.js.

So, besides many build scripts, sync scripts and other scripts my home computing relies on, I wrote this simple one, which someone may find useful. It generates comment headers like that:

//# Comment ---------------------------------------
//                                             #
//   ###                                       #
//  #   #   ###   ## #   ## #    ###   ####   #####
//  #      #   #  # # #  # # #  #   #  #   #   #
//  #      #   #  # # #  # # #  #####  #   #   #
//  #      #   #  # # #  # # #  #      #   #   #
//  #   #  #   #  # # #  # # #  #      #   #   #
//   ###    ###   # # #  # # #   ####  #   #    ###

The script detects a special line, starting with "//#" and extends (or replaces) the following comment section with the same "banner"-style text. You can process source files, it will update all the comments in them. Original text will be saved under ".sav" extension.

Why would you need that? If you are using an editor which shows small preview of entire file, like Sublime or recent Visual Studio, you can actually read that banner in that small preview. So, if you work with long files, its easier to navigate between code sections just scrolling the preview up to the readable marker.

Also, you can make a different form of banner, like on screenshot, which only works when you have Unicode fonts with block characters, like on Mac computers. Windows fonts do not have this range, usually, but, there is a free font "DejaVu Sans Mono", which displays that Unicode range correctly. In this case you have 2x2 block pixels per character, so the text is twice more compact.

The script can be downloaded here. Obviously you would need node.js to run it.

Usage:
  • node bnr.js [ -a | -u | -n ] [-0 | -1 | -2 | -3 | -4 ] -f file.c file.h -- replace comments in two files
  • node bnr.js [ -a | -u | -n ] [-0 | -1 | -2 | -3 | -4 ] text -- print text
  • node bnr.js [ -a | -u | -n ] [-0 | -1 | -2 | -3 | -4 ] -- print character set
Options:
  • -a -- Ascii mode, '#' per pixel
  • -u -- Unicode block mode
  • -n -- remove banners from comments
  • -0 -- default font (my old "Forecast")
  • -1..4 -- other fonts

No comments: