Skip to content

Instantly share code, notes, and snippets.

@kennydude
Created September 16, 2014 21:21
Show Gist options
  • Save kennydude/5430220d016a632dff65 to your computer and use it in GitHub Desktop.
Save kennydude/5430220d016a632dff65 to your computer and use it in GitHub Desktop.
How PowerLine Works

How Does The Powerline thing work?

I recently was enlightened to Powerlines, the cool terminal thing that looks really cool.

But, me being me I wanted to know how this thing worked, but nobody has wrote anything and I've found out.

Basically the "patched fonts" just add some symbols like arrows and git icons so they render in your terminal properly.

By Powerline, I mean this thing:

Powerline

It's rather clever, but it's actually a very simple trick. One of the symbols is just a arrow which is the full height of the line, which means with some NodeJS we can replicate it:

  var ansi = require("ansi");
  var cursor = ansi(process.stdout);
  
  cursor.white().bg.green().write(" Hello World ");
  
  cursor.green().bg.blue().write("\ue0b0"); // this is the arrow symbol
  
  cursor.white().write(" POWERLINE ");
  
  cursor.blue().bg.reset().write("\ue0b0");
  
  cursor.reset().write("\n");

This will look like so:

Result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment