<commit_before>#!/usr/bin/python3

import fileinput
import termbox
import time
import math
import re

def getNumWindows(lines, height):
    return max(math.ceil(len(lines) / height), 1)
def getWindowToPutLineInto(index, height):
    return int(index / height)
def getLinesToDisplay(lines, height, startingIndex):
    return min(len(lines) - startingIndex, height)

if __name__ == '__main__':
    lines = []

    for line in fileinput.input():
        lines.append(line)

    t = termbox.Termbox()

    height = t.height()

    numWindows = getNumWindows(lines, height)

    windowIndex = 0

    windows = [[] for i in range(numWindows)]

    width = t.width()

    for i in range(len(lines)):
        windows[getWindowToPutLineInto(i, height)].append(lines[i])

    items = []

    while True:
        t.clear()
        startingIndex = windowIndex * height
        window = windows[windowIndex]
        items.append(window[0])
        for y in range(len(window)):
            for x in range(min(len(window[y][:-1] if window[y][-1] == '\n' else window[y]), width)):
                t.change_cell(x, y, ord(window[y][x]), termbox.DEFAULT, termbox.DEFAULT)
        t.present()
        char = t.poll_event()
        if char[1] == 'q':
            break
        elif char[1] == 'j':
            windowIndex = (windowIndex + 1) % numWindows
        elif char[1] == 'k':
            windowIndex = (windowIndex - 1) % numWindows

    t.close()<commit_msg>Fixed tab handling, sort of<commit_after>#!/usr/bin/python3

import fileinput
import termbox
import time
import math
import re

def getNumWindows(lines, height):
    return max(math.ceil(len(lines) / height), 1)
def getWindowToPutLineInto(index, height):
    return int(index / height)
def getLinesToDisplay(lines, height, startingIndex):
    return min(len(lines) - startingIndex, height)
def tabConvert(line):
    result = ''
    screenIndex = 0
    for charIndex in range(len(line)):
        if line[charIndex] == '\t':
            result += ' ' * (8 - screenIndex % 8)
            screenIndex += 8 - screenIndex % 8
        else:
            result += line[charIndex]
            screenIndex += 1
    return result

if __name__ == '__main__':
    lines = []

    for line in fileinput.input():
        lines.append(line)

    t = termbox.Termbox()

    height = t.height()

    numWindows = getNumWindows(lines, height)

    windowIndex = 0

    windows = [[] for i in range(numWindows)]

    width = t.width()

    for i in range(len(lines)):
        windows[getWindowToPutLineInto(i, height)].append(tabConvert(lines[i]))

    items = []

    while True:
        t.clear()
        startingIndex = windowIndex * height
        window = windows[windowIndex]
        items.append(window[0])
        for y in range(len(window)):
            for x in range(min(len(window[y][:-1] if window[y][-1] == '\n' else window[y]), width)):
                t.change_cell(x, y, ord(window[y][x]), termbox.DEFAULT, termbox.DEFAULT)
        t.present()
        char = t.poll_event()
        if char[1] == 'q':
            break
        elif char[1] == 'j':
            windowIndex = (windowIndex + 1) % numWindows
        elif char[1] == 'k':
            windowIndex = (windowIndex - 1) % numWindows

    t.close()
{'fraction_non_alphanumeric': 0.13450292397660818, 'fraction_numerical': 0.008618036318867343, 'mean_word_length': 2.4871244635193133, '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': '2702273', 'n_tokens_mistral': 1037, 'n_tokens_neox': 995, 'n_words': 258}