Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created January 14, 2016 16:53
Show Gist options
  • Save jpmens/f4d8819b0d4a0821c0f3 to your computer and use it in GitHub Desktop.
Save jpmens/f4d8819b0d4a0821c0f3 to your computer and use it in GitHub Desktop.
patch wscat to display pretty JSON
*** /usr/local/bin/wscat.orig 2016-01-14 17:47:00.000000000 +0100
--- /usr/local/bin/wscat 2016-01-14 17:51:37.000000000 +0100
***************
*** 211,217 ****
wsConsole.print('error: ' + code + (description ? ' ' + description : ''), Console.Colors.Yellow);
process.exit(-1);
}).on('message', function message(data, flags) {
! wsConsole.print('< ' + data, Console.Colors.Blue);
});
wsConsole.on('close', function close() {
--- 211,223 ----
wsConsole.print('error: ' + code + (description ? ' ' + description : ''), Console.Colors.Yellow);
process.exit(-1);
}).on('message', function message(data, flags) {
! var s;
! try {
! s = JSON.stringify(JSON.parse(data), null, 4);
! } catch (e) {
! s = data;
! }
! wsConsole.print('< ' + s, Console.Colors.Blue);
});
wsConsole.on('close', function close() {
@damianobarbati
Copy link

cool! would you make a PR on wscat repo? Enabled this with a flag would be awesome.

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