Exemple #1
0
def save():
    global piDigits, terminalSize
    global lastPosition
    global keyHandler
    pause()
    oldKeys = keyHandler.actions
    keyHandler.actions = {"default": bellButItTakesArgs}

    t.sleep(0.02)

    digitChunks = f.splitString(piDigits, (len(piDigits) // 100) +
                                1)  #split digits into a 100 chunks

    f.write("pi.txt", "")  #delete digits that are already there

    tf.moveCursor(to={"row": lastPosition[1] + 1, "column": 0})
    tf.clear(line=True)

    for digit in f.everyIndexInList(digitChunks):  #save the digits
        f.appendTo("pi.txt", digitChunks[digit])  #append the next chunk
        tf.changeStyle(italic=True, invert=True, bold=True)
        tf.print("{}% done saving".format(digit + 1))
        tf.moveCursor(to={
            "row": lastPosition[1] + 1,
            "column": 0
        })  #go to bottom left

    if pause:
        unPause()

    keyHandler.actions = oldKeys