<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# @file tP.py
# @brief 
# @author <EMAIL>
# @version 0.1.00
# @date 2015-05-09

import curses
import os
import sys
from time import sleep
import locale
from content import Content

locale.setlocale(locale.LC_ALL, '')
default_line_time = 0.5

class TerminalPresentation:
    def __init__(self, file_path):
        self.__init_win()
        content = Content(file_path)
        self.image_path = os.path.dirname(file_path)
        self.presentation_content = content.get_content_list()
        self.currentpath = os.getcwd()
        try:
            self.show_str("tP by jinsheng, press 'j' to continue", 0, False)
            self.start()
        except KeyboardInterrupt:
            pass
        self.__reset_background()
        curses.endwin()
    
    def __init_win(self):
        self.screen = curses.initscr()
        self.screen.keypad(True)
        curses.noecho()
        curses.cbreak()
        self.height, self.width = self.screen.getmaxyx()

    def start(self):
        key = 0
        page_size = len(self.presentation_content)
        current_page = -1
        while True:
            if key == ord('q'):
                break
            elif key in (ord('j'), curses.KEY_DOWN, curses.KEY_RIGHT):
                self.__page_duang_after(self.presentation_content[current_page]["attribute"])
                if current_page < page_size - 1:
                    current_page += 1
                self.show_page(self.presentation_content[current_page])
            elif key in (ord('k'), curses.KEY_UP, curses.KEY_LEFT):
                if current_page > 0:
                    current_page -= 1
                elif current_page == -1:
                    current_page = 0
                self.show_page(self.presentation_content[current_page])


            key = self.screen.getch()

    def show_page(self, page_info):
        page_attribute = page_info["attribute"]
        page_content = page_info["content"]
        self.__reset_background()
        self.__page_duang_before(page_attribute)
        if "session" in page_attribute:
            start_y = self.__get_start_y(len(page_content) + 4)
            self.show_str("======❧❦☙======", start_y, False)
            self.show_str("======❧❦☙======", start_y + len(page_content) + 3, False)
            for i in range(0, len(page_content)):
                content_txt = page_content[i]["content"]
                self.show_str(content_txt, start_y + i + 2, True)
        elif "image" in page_attribute :
            image_path = page_info["content"][0]["content"]
            self.__set_background(os.path.join(self.image_path, image_path))

        elif "body" in page_attribute:
            start_y = self.__get_start_y(len(page_content))
            for i in range(0, len(page_content)):
                content_txt = page_content[i]["content"]
                self.__content_duang(content_txt, page_content[i]["attribute"], start_y + i)

        elif "code" in page_attribute :
            start_y = self.__get_start_y(len(page_content))
            max_len = 0
            max_len_index = 0
            for i in range(0, len(page_content)):
                content_txt = page_content[i]["content"]
                code_len = len(content_txt)
                for index in content_txt:
                    if self.__is_cn_char(index):
                        code_len += 1
                if code_len > max_len:
                    max_len = code_len
                    max_len_index = i
            start_x = self.__get_start_x(page_content[max_len_index]["content"])
            for i in range(0, len(page_content)):
                if "getch" in page_content[i]["attribute"]:
                    self.screen.getch()
                content_txt = page_content[i]["content"]
                self.show_code(content_txt, start_y + i, start_x, True)

    #页面特效判断
    def __page_duang_before(self, attribute):
        if "flash" in attribute:
            self.__clr()
            curses.flash()
        if "slip" in attribute:
            self.__slip_into()
        self.__clr()

    def __page_duang_after(self, attribute):
        if "printtonext" in attribute:
            height = self.height
            self.__print_with_sleep(":next page", 0, height - 1)

    def __content_duang(self, content_txt, attribute, start_y):
        if "getch" in attribute:
                self.screen.getch()
        if "printer" in attribute:
            self.show_str(content_txt, start_y, True)
        else:
            self.show_str(content_txt, start_y, False)

        if "flash" in attribute:
            curses.flash()

    def show_str(self, printstr, height, sleep):
        start_x = self.__get_start_x(printstr)
        if sleep == True:
            self.__print_with_sleep(printstr, start_x, height)
        else:
            self.__print_without_sleep(printstr, start_x, height)

    def show_code(self, printstr, height, start_x, sleep):
        if sleep == True:
            self.__print_with_sleep(printstr, start_x, height)
        else:
            self.__print_without_sleep(printstr, start_x, height)
<commit_msg>add image for content<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# @file tP.py
# @brief 
# @author <EMAIL>
# @version 0.1.00
# @date 2015-05-09

import curses
import os
import sys
from time import sleep
import locale
from content import Content

locale.setlocale(locale.LC_ALL, '')
default_line_time = 0.5

class TerminalPresentation:
    def __init__(self, file_path):
        self.__init_win()
        content = Content(file_path)
        self.image_path = os.path.dirname(file_path)
        self.presentation_content = content.get_content_list()
        self.currentpath = os.getcwd()
        try:
            self.show_str("tP by jinsheng, press 'j' to continue", 0, False)
            self.start()
        except KeyboardInterrupt:
            pass
        self.__reset_background()
        curses.endwin()
    
    def __init_win(self):
        self.screen = curses.initscr()
        self.screen.keypad(True)
        curses.noecho()
        curses.cbreak()
        self.height, self.width = self.screen.getmaxyx()

    def start(self):
        key = 0
        page_size = len(self.presentation_content)
        current_page = -1
        while True:
            if key == ord('q'):
                break
            elif key in (ord('j'), curses.KEY_DOWN, curses.KEY_RIGHT):
                self.__page_duang_after(self.presentation_content[current_page]["attribute"])
                if current_page < page_size - 1:
                    current_page += 1
                self.show_page(self.presentation_content[current_page])
            elif key in (ord('k'), curses.KEY_UP, curses.KEY_LEFT):
                if current_page > 0:
                    current_page -= 1
                elif current_page == -1:
                    current_page = 0
                self.show_page(self.presentation_content[current_page])


            key = self.screen.getch()

    def show_page(self, page_info):
        page_attribute = page_info["attribute"]
        page_content = page_info["content"]
        self.__reset_background()
        self.__page_duang_before(page_attribute)
        if "session" in page_attribute:
            start_y = self.__get_start_y(len(page_content) + 4)
            self.show_str("======❧❦☙======", start_y, False)
            self.show_str("======❧❦☙======", start_y + len(page_content) + 3, False)
            for i in range(0, len(page_content)):
                content_txt = page_content[i]["content"]
                self.show_str(content_txt, start_y + i + 2, True)
        elif "image" in page_attribute :
            image_path = page_info["content"][0]["content"]
            self.__set_background(os.path.join(self.image_path, image_path))

        elif "body" in page_attribute:
            start_y = self.__get_start_y(len(page_content))
            for i in range(0, len(page_content)):
                content_txt = page_content[i]["content"]
                self.__content_duang(content_txt, page_content[i]["attribute"], start_y + i)

        elif "code" in page_attribute :
            start_y = self.__get_start_y(len(page_content))
            max_len = 0
            max_len_index = 0
            for i in range(0, len(page_content)):
                content_txt = page_content[i]["content"]
                code_len = len(content_txt)
                for index in content_txt:
                    if self.__is_cn_char(index):
                        code_len += 1
                if code_len > max_len:
                    max_len = code_len
                    max_len_index = i
            start_x = self.__get_start_x(page_content[max_len_index]["content"])
            for i in range(0, len(page_content)):
                if "getch" in page_content[i]["attribute"]:
                    self.screen.getch()
                content_txt = page_content[i]["content"]
                self.show_code(content_txt, start_y + i, start_x, True)

    #页面特效判断
    def __page_duang_before(self, attribute):
        if "flash" in attribute:
            self.__clr()
            curses.flash()
        if "slip" in attribute:
            self.__slip_into()
        self.__clr()

    def __page_duang_after(self, attribute):
        if "printtonext" in attribute:
            height = self.height
            self.__print_with_sleep(":next page", 0, height - 1)

    def __content_duang(self, content_txt, attribute, start_y):
        if "getch" in attribute:
            self.screen.getch()
        if "image" in attribute:
            self.screen.getch()
            self.__set_background(os.path.join(self.image_path, content_txt))
            self.screen.getch()
            self.__reset_background()
            return
        if "printer" in attribute:
            self.show_str(content_txt, start_y, True)
        else:
            self.show_str(content_txt, start_y, False)

        if "flash" in attribute:
            curses.flash()

    def show_str(self, printstr, height, sleep):
        start_x = self.__get_start_x(printstr)
        if sleep == True:
            self.__print_with_sleep(printstr, start_x, height)
        else:
            self.__print_without_sleep(printstr, start_x, height)

    def show_code(self, printstr, height, start_x, sleep):
        if sleep == True:
            self.__print_with_sleep(printstr, start_x, height)
        else:
            self.__print_without_sleep(printstr, start_x, height)

{'fraction_non_alphanumeric': 0.10733232284956423, 'fraction_numerical': 0.007010231148162183, 'mean_word_length': 2.0102651839178787, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 9, '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': '5113099', 'n_tokens_mistral': 3301, 'n_tokens_neox': 3153, 'n_words': 657}