<commit_before>import unicurses as curses
from .textuserinterface import TextUserInterface
from logging import debug, info
import os


# Lower the annoying delay for the escape character
# VIM also uses 25 ms
os.environ['ESCDELAY'] = '25'


def init_colors(stdscr):
    # Initialize color pairs from the terminal color palette
    # Pair 0 is the default, pairs 1-16 are the palette colors,
    # pairs 17-32 are palette colors with a different background.
    # We assume that color 8 has good contrast with other colors.

    global HAS_COLORS
    HAS_COLORS = curses.has_colors()
    #HAS_COLORS = False

    if HAS_COLORS:
        curses.start_color()
        curses.use_default_colors()

        global HAS_BACKGROUND_COLORS
        HAS_BACKGROUND_COLORS = True
        if HAS_BACKGROUND_COLORS:
            info('Terminal supports background colors.')
        else:
            info('Terminal does not support background colors.')

        global COLOR_PAIRS
        #COLOR_PAIRS = min(16, curses.COLORS)
        COLOR_PAIRS = 16
        info('Terminal supports {} colors. Using {} colorpairs.'
             .format(16, COLOR_PAIRS))

        for i in range(COLOR_PAIRS):
            curses.init_pair(i + 1, i, -1)
            try:
                curses.init_pair(i + 1 + COLOR_PAIRS, i, 8)
                curses.init_pair(i + 1 + COLOR_PAIRS + COLOR_PAIRS, i, 9)
            except:
                HAS_BACKGROUND_COLORS = False


def start(filenames):
    """Initialize curses and start application."""
    curses.def_shell_mode()
    stdscr = curses.initscr()

    # Display settings
    curses.cbreak()
    curses.noecho()

    # Key input settings
    curses.raw()
    stdscr.keypad(1)

    # No cursor
    curses.curs_set(0)

    try:
        # Init colors
        init_colors(stdscr)

        # Create all interfaces
        for filename in filenames:
            ui = TextUserInterface(stdscr, filename)

        ui.activate()
    except:
        raise
    finally:
        curses.reset_shell_mode()

        # Restore cursor
        curses.curs_set(1)<commit_msg>reset of term settings substituted by endwin() call<commit_after>import unicurses as curses
from .textuserinterface import TextUserInterface
from logging import debug, info
import os


# Lower the annoying delay for the escape character
# VIM also uses 25 ms
os.environ['ESCDELAY'] = '25'


def init_colors(stdscr):
    # Initialize color pairs from the terminal color palette
    # Pair 0 is the default, pairs 1-16 are the palette colors,
    # pairs 17-32 are palette colors with a different background.
    # We assume that color 8 has good contrast with other colors.

    global HAS_COLORS
    HAS_COLORS = curses.has_colors()
    #HAS_COLORS = False

    if HAS_COLORS:
        curses.start_color()
        curses.use_default_colors()

        global HAS_BACKGROUND_COLORS
        HAS_BACKGROUND_COLORS = True
        if HAS_BACKGROUND_COLORS:
            info('Terminal supports background colors.')
        else:
            info('Terminal does not support background colors.')

        global COLOR_PAIRS
        #COLOR_PAIRS = min(16, curses.COLORS)
        COLOR_PAIRS = 16
        info('Terminal supports {} colors. Using {} colorpairs.'
             .format(16, COLOR_PAIRS))

        for i in range(COLOR_PAIRS):
            curses.init_pair(i + 1, i, -1)
            try:
                curses.init_pair(i + 1 + COLOR_PAIRS, i, 8)
                curses.init_pair(i + 1 + COLOR_PAIRS + COLOR_PAIRS, i, 9)
            except:
                HAS_BACKGROUND_COLORS = False


def start(filenames):
    """Initialize curses and start application."""
    stdscr = curses.initscr()

    # Display settings
    curses.cbreak()
    curses.noecho()

    # Key input settings
    curses.raw()
    stdscr.keypad(1)

    # No cursor
    curses.curs_set(0)

    try:
        # Init colors
        init_colors(stdscr)

        # Create all interfaces
        for filename in filenames:
            ui = TextUserInterface(stdscr, filename)

        ui.activate()
    except:
        raise
    finally:
        curses.endwin()
{'fraction_non_alphanumeric': 0.07669831994156319, 'fraction_numerical': 0.013391770148526905, 'mean_word_length': 2.281150159744409, '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': '1949436', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1209, 'n_words': 360}