<commit_before># -*- coding: utf-8
""" smashlib.util
"""
import os
import StringIO
import threading

import asciitable

import IPython
from IPython import ColorANSI
from IPython.genutils import Term

opj = os.path.join
ope = os.path.exists
tc = ColorANSI.TermColors()

def home(): return os.environ['HOME']

def truncate_fpath(fpath):
    return fpath.replace(home(), '~')

def get_prompt_t():
    """ get the current prompt template """
    opc = getattr(__IPYTHON__.shell, 'outputcache', None)
    if opc:
        return opc.prompt1.p_template
    else:
        return 'error-getting-output-prompt'


def set_prompt_t(t):
    """ set the current prompt template """
    opc = getattr(__IPYTHON__.shell, 'outputcache', None)
    if opc:
        opc.prompt1.p_template = t


def post_hook_for_magic(original_magic_name, new_func):
    """ attach a new post-run hook for an existing magic function """
    #print 'chaining',original_magic_name,new_func
    old_magic = getattr(__IPYTHON__, 'magic_' + original_magic_name)
    new_name = '_magic_{0}_chain'.format(original_magic_name)
    chain = getattr(__IPYTHON__, new_name, [])
    if not chain:
        def new_magic(self, parameter_s=''):
            out = old_magic(parameter_s=parameter_s)
            chain = getattr(__IPYTHON__, '_magic_{0}_chain'.format(original_magic_name), [])
            for f in chain:<commit_msg>nicer prompt abstraction<commit_after># -*- coding: utf-8
""" smashlib.util
"""
import os
import StringIO
import threading

import asciitable

import IPython
from IPython import ColorANSI
from IPython.genutils import Term

opj = os.path.join
ope = os.path.exists
tc = ColorANSI.TermColors()

def home(): return os.environ['HOME']

def truncate_fpath(fpath):
    return fpath.replace(home(), '~')

class Prompt(object):
    """ wrapping ipython internals, """
    def _get_template(self):
        """ get the current prompt template """
        opc = getattr(__IPYTHON__.shell, 'outputcache', None)
        if opc:
            return opc.prompt1.p_template
        else:
            return 'error-getting-output-prompt'
    def _set_template(self, t):
        """ set the current prompt template """
        opc = getattr(__IPYTHON__.shell, 'outputcache', None)
        if opc:
            opc.prompt1.p_template = t
    template = property(_get_template, _set_template)
prompt = Prompt()

def post_hook_for_magic(original_magic_name, new_func):
    """ attach a new post-run hook for an existing magic function """
    #print 'chaining',original_magic_name,new_func
    old_magic = getattr(__IPYTHON__, 'magic_' + original_magic_name)
    new_name = '_magic_{0}_chain'.format(original_magic_name)
    chain = getattr(__IPYTHON__, new_name, [])
    if not chain:
        def new_magic(self, parameter_s=''):
            out = old_magic(parameter_s=parameter_s)
            chain = getattr(__IPYTHON__, '_magic_{0}_chain'.format(original_magic_name), [])
            for f in chain:
{'fraction_non_alphanumeric': 0.11359026369168357, 'fraction_numerical': 0.0033806626098715348, 'mean_word_length': 3.559322033898305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1835208', 'n_tokens_mistral': 994, 'n_tokens_neox': 955, 'n_words': 228}