<commit_before>Chalk = require \chalk
G     = require \growly
Util  = require \util
Const = require \./constants

const CHALKS = error:Chalk.red, info:Chalk.stripColor, success:Chalk.green
enabled = (growl-at = process.env.growl-at)?

function register cb
  log "growl.register #{Const.APPNAME}"
  err <- G.register Const.APPNAME, [{label:\error} {label:\info} {label:\success}]
  log err if err
  cb err

function send label, item, opts = {}
  text = Chalk.stripColor if item instanceof Error then item.message else item
  Util.log CHALKS[label] text unless opts.nolog
  return unless enabled
  title = "#{Const.APPNAME} #label".toUpperCase!
  # for some reason a '::' causes the growl to fail !?
  t = text.replace /::/g \:
  o = (label:label, title:title) <<< opts
  err <- G.notify t, o
  if err then log err else return
  err <- register # send failed -- attempt to re-register then re-send
  return if err
  err <- G.notify t, o
  log err if err

module.exports =
  alert: (err, opts)  -> send \error err, (sticky:true) <<< opts
  err  : (err, opts)  -> send \error err, opts
  ok   : (text, opts) -> send \success text, opts
  say  : (text, opts) -> send \info text, opts

return log "growl disabled" unless enabled
log "growl at #growl-at"

G.setHost growl-at
register -><commit_msg>refactor<commit_after>Chalk = require \chalk
G     = require \growly
Util  = require \util
Const = require \./constants

const CHALKS = error:Chalk.red, info:Chalk.stripColor, success:Chalk.green
enabled = (growl-at = process.env.growl-at)?

function register cb
  log "growl.register #{Const.APPNAME} to growl at #growl-at"
  err <- G.register Const.APPNAME, [{label:\error} {label:\info} {label:\success}]
  log err if err
  cb err

function send label, item, opts = {}
  text = Chalk.stripColor if item instanceof Error then item.message else item
  Util.log CHALKS[label] text unless opts.nolog
  return unless enabled
  title = "#{Const.APPNAME} #label".toUpperCase!
  # for some reason a '::' causes the growl to fail !?
  t = text.replace /::/g \:
  o = (label:label, title:title) <<< opts
  err <- G.notify t, o
  if err then log err else return
  err <- register # send failed -- attempt to re-register then re-send
  return if err
  err <- G.notify t, o
  log err if err

module.exports =
  alert: (err, opts)  -> send \error err, (sticky:true) <<< opts
  err  : (err, opts)  -> send \error err, opts
  ok   : (text, opts) -> send \success text, opts
  say  : (text, opts) -> send \info text, opts

return log "growl disabled" unless enabled
G.setHost growl-at
register ->
{'fraction_non_alphanumeric': 0.12980956082394093, 'fraction_numerical': 0.0, 'mean_word_length': 3.3043478260869565, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4841675', 'n_tokens_mistral': 873, 'n_tokens_neox': 864, 'n_words': 308}