<commit_before># -*- coding: utf-8 -*-
import curses
import pdb
import sys


screen = None
initialized = False


def init(stdscr):
    global screen
    screen = stdscr
    global initialized
    initialized = True


def finalize(stdscr):
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()


def debug(stdscr=screen):
    if not initialized:
        raise Exception('cursutils must be initialized first')
    if not stdscr:
        raise Exception('stdscr must be a valid window object')
    finalize(stdscr)

    debugger = pdb.Pdb()
    debugger.reset()
    debugger.do_where(None)
    users_frame = sys._getframe().f_back  # One frame up, outside this function
    debugger.interaction(users_frame, None)


# Use with:
# import cursutils
# cursutils.init(stdscr)   # where stdscr is a curses window object
# cursutils.debug(cursutils.screen)
<commit_msg>simplify cursutils initialization<commit_after># -*- coding: utf-8 -*-
import curses
import pdb
import sys


screen = None


def init(stdscr):
    global screen
    screen = stdscr


def finalize(stdscr=None):
    if not stdscr and not screen:
        raise Exception('either call init() first or provide a valid window object')
    stdscr = screen if screen and not stdscr else stdscr
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()


def debug(stdscr=None):
    if not stdscr and not screen:
        raise Exception('either call init() first or provide a valid window object')
    stdscr = screen if screen and not stdscr else stdscr
    finalize(stdscr)

    debugger = pdb.Pdb()
    debugger.reset()
    debugger.do_where(None)
    users_frame = sys._getframe().f_back  # One frame up, outside this function
    debugger.interaction(users_frame, None)


# Use with:
# import cursutils
# cursutils.init(stdscr)   # where stdscr is a `curses` Window object
# cursutils.debug()

{'fraction_non_alphanumeric': 0.09162717219589257, 'fraction_numerical': 0.00210637177461822, 'mean_word_length': 3.3378995433789953, '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': '5289698', 'n_tokens_mistral': 606, 'n_tokens_neox': 585, 'n_words': 186}