Esempio n. 1
0
def countdown_command(cmds):
    try:
        cmds[1] = cmds[1].lower()
        if cmds[1] == "new" and screenfunctions.indexists(cmds, 2, 3):
            if screenfunctions.indexists(cmds, 4):
                superglobals.countdown_list.append(
                    Countdown(cmds[4], int(cmds[2]), int(cmds[3]), (True, )))
                return 0
            superglobals.countdown_list.append(
                Countdown(f"countdown {len(superglobals.countdown_list)}",
                          int(cmds[2]), int(cmds[3]), (True, )))
        if cmds[1] in ["remove", "del"] and screenfunctions.indexists(cmds, 2):
            del superglobals.countdown_list[int(cmds[2])]
        return 0
    except Exception as e:
        superglobals.error_list.append(e)
Esempio n. 2
0
def timer_command(cmds):
    try:
        cmds[1] = cmds[1].lower()
        if cmds[1] == "new" and screenfunctions.indexists(cmds, 2):
            if screenfunctions.indexists(cmds, 3):

                superglobals.timer_list.append(
                    Timer(cmds[3], float(cmds[2]), (True, )))
                return 0

            superglobals.timer_list.append(
                Timer(f"timer {len(superglobals.timer_list) + 1}",
                      float(cmds[2]), (True, )))

        if cmds[1] in ["remove", "del"] and screenfunctions.indexists(cmds, 2):
            del superglobals.timer_list[int(cmds[2])]
        if cmds[1] == "reset" and screenfunctions.indexists(cmds, 2):
            superglobals.timer_list[int(cmds[2])].seconds = \
            time.perf_counter() + \
            superglobals.timer_list[int(cmds[2])].minutes_until_alarm
        return 0
    except Exception as e:
        superglobals.error_list.append(e)
Esempio n. 3
0
def stopwatch_command(cmds):
    try:
        cmds[1] = cmds[1].lower()
        if cmds[1] == "new":
            if screenfunctions.indexists(cmds, 2):

                superglobals.stopwatch_list.append(
                    Stopwatch(cmds[2], time.perf_counter()))

                return 0

            superglobals.stopwatch_list.append(
                Stopwatch(f"stopwatch {len(superglobals.stopwatch_list)}",
                          time.perf_counter()))

        if cmds[1] in ["remove", "del"] and screenfunctions.indexists(cmds, 2):
            del superglobals.stopwatch_list[int(cmds[2])]
        if cmds[1] == "reset" and screenfunctions.indexists(cmds, 2):
            superglobals.stopwatch_list[int(
                cmds[2])].seconds = time.perf_counter()
        return 0
    except Exception as e:
        superglobals.error_list.append(e)
Esempio n. 4
0
def main(stdscr):

    page = 0

    max_y = stdscr.getmaxyx()[0] - 1
    max_x = stdscr.getmaxyx()[1] - 1

    def resizing_thread_function():
        while True:
            if max_y < 39 or max_x < 159:
                print("\x1b[8;40;160t")

    def read_file(file_path, max_y, max_x):

        curses.echo(False)

        def resizing_thread_function():
            while True:
                if max_y < 39 or max_x < 159:
                    print("\x1b[8;40;160t")

        resizing_thread = threading.Thread(target=resizing_thread_function,
                                           daemon=True)
        resizing_thread.start()

        page = 0
        superglobals.state = "fileread"
        contents = []
        with open(file_path, "r") as file:
            contents = file.readlines()

        display_contents = contents
        for i in range(page * max_y, (page + 1) * max_y):
            if screenfunctions.indexists(display_contents, i):
                if len(display_contents[i]) > max_x - 44:
                    display_contents.insert(i + 1,
                                            display_contents[i][max_x - 45:])
                    display_contents[i] = display_contents[i][:max_x - 45]

        curses.curs_set(False)
        k = 0
        while k != ord('q'):
            #try:
            max_y = stdscr.getmaxyx()[0] - 1
            max_x = stdscr.getmaxyx()[1] - 1

            if max_y >= 39 and max_x >= 159:
                if superglobals.information_enabled_setting:
                    superglobals.information_enabled = True

                stdscr.erase()

                screenfunctions.render_defaults(stdscr)

                contents = []
                with open(file_path, "r") as file:
                    contents = file.readlines()

                display_contents = contents
                for i, _ in enumerate(display_contents):
                    if screenfunctions.indexists(display_contents, i):
                        if len(display_contents[i]) > max_x - 44:
                            display_contents.insert(
                                i + 1, display_contents[i][max_x - 45:])
                            display_contents[i] = display_contents[i][:max_x -
                                                                      45]

                for index, line_num in enumerate(
                        range(page * max_y, (page + 1) * max_y)):
                    if screenfunctions.indexists(display_contents, line_num):
                        stdscr.addstr(index, 44, display_contents[line_num])

                stdscr.attron(curses.A_REVERSE)
                stdscr.addstr(
                    max_y, 44,
                    "Press 'q' to exit, ARROW KEYS to change pages." + " " *
                    (max_x - 90))
                stdscr.addstr(max_y, max_x - 9, f"Page: {page}")
                stdscr.attroff(curses.A_REVERSE)

                k = stdscr.getch()

                if k == ord('q'):
                    break

                if k == curses.KEY_RIGHT and page < 255:
                    page += 1

                if k == curses.KEY_LEFT and page > 0:
                    page -= 1

            if max_y < 39 or max_x < 159:
                superglobals.information_enabled = False
                stdscr.addstr(
                    0, 0, "Py-Shell requires atleast a 160x40 window size.")
                stdscr.getch()
                stdscr.erase()

        # except Exception as e:
        #     superglobals.error_list.append(e)

    resizing_thread = threading.Thread(target=resizing_thread_function,
                                       daemon=True)
    resizing_thread.start()

    while True:
        #try:
        curses.curs_set(False)
        curses.echo(False)

        max_y = stdscr.getmaxyx()[0] - 1
        max_x = stdscr.getmaxyx()[1] - 1

        if max_y >= 39 and max_x >= 159:

            if superglobals.information_enabled_setting:
                superglobals.information_enabled = True

            current_directory = os.getcwd()
            current_items = os.listdir(current_directory)

            stdscr.erase()

            screenfunctions.render_defaults(stdscr)

            stdscr.addstr(1, 45, f"Current Directory :: {current_directory}")
            stdscr.addstr(1, max_x - 9, f"Page: {page}")

            # Draws the two barriers.
            screenfunctions.draw_box(stdscr, 0, 44, 2, max_x - 44, 1)
            screenfunctions.draw_box(stdscr, 3, 44, max_y - 4, max_x - 44, 1)

            # Formula for amount of files on a single page (if it is full)
            # int((max_x - 45) / 45) * (max_y - 6)
            # (int((max_x - 45) / 45) * (max_y - 6)) * page

            # Draws all the files

            # Sees if the longest filename is above 45, if it is, it sets the column modulus to that filename's length.
            column_modulus = len(max(current_items, key=len)) + 5 if len(
                max(current_items, key=len)) > 45 else 45
            for i in range(int((max_x - 45) / column_modulus)):
                for ii in range(4, max_y - 1):
                    # (If you are debugging this, I apologize heavily.)
                    if screenfunctions.indexists(
                            current_items,
                        ((ii - 4) + (max_y - 5) * i) + (int(
                            (max_x - 45) / column_modulus) *
                                                        (max_y - 6)) * page):
                        stdscr.addstr(
                            ii, 45 + i * column_modulus,
                            f"{(ii + (max_y - 5) * i - 4) + (int((max_x - 45) / column_modulus) * (max_y - 6)) * page} : {current_items[((ii - 4) + (max_y - 5) * i) + (int((max_x - 45) / column_modulus) * (max_y - 6)) * page]}"
                        )

            k = stdscr.getch()

            if k == ord(';'):
                curses.echo(True)
                #curses.cur_set(True)

                # Gets input from the user.
                input_string = screenfunctions.curses_input(
                    stdscr, int(max_y / 2), 0, f"{superglobals.state}:: ",
                    42 - len(superglobals.state) - 3)

                # Converts it into commands.
                cmds = input_string.split("; ")
                cmds[0] = cmds[0].lower()

                if cmds[0] == "cd":
                    # Handling if the User inputs a path to a directory in the current directory.
                    if os.path.isdir(os.path.join(os.getcwd(), cmds[1])):
                        os.chdir(os.path.join(os.getcwd(), cmds[1]))

                    # Handling if the User inputs a path to a directory not in the current directory.
                    if os.path.isdir(cmds[1]):
                        os.chdir(cmds[1])

                    # Handling if the User inputs ".."
                    if cmds[1] == ".." and current_directory != "/":
                        os.chdir(os.path.dirname(current_directory))

                if cmds[0] in ["r", "read"] and screenfunctions.indexists(
                        cmds, 1):
                    if os.path.isfile(os.path.join(os.getcwd(), cmds[1])):
                        read_file(os.path.join(os.getcwd(), cmds[1]), max_y,
                                  max_x)

                    # if os.path.isfile(cmds[1]):
                    #     read_file(cmds[1], max_y, max_x)

                    superglobals.state = "multife"

                if cmds[0] == "exit":
                    break

                if cmds[0] == "quit":
                    sys.exit(0)

                #curs_set(False)

            if k == curses.KEY_RIGHT and page < 255:
                page += 1

            if k == curses.KEY_LEFT and page > 0:
                page -= 1

        if max_y < 39 or max_x < 159:
            superglobals.information_enabled = False
            stdscr.addstr(0, 0,
                          "Py-Shell requires atleast a 160x40 window size.")
            stdscr.getch()
            stdscr.erase()

    # except Exception as e:
    #     superglobals.error_list.append(e)
    curses.echo(True)
    curses.curse_set(True)
Esempio n. 5
0
    def read_file(file_path, max_y, max_x):

        curses.echo(False)

        def resizing_thread_function():
            while True:
                if max_y < 39 or max_x < 159:
                    print("\x1b[8;40;160t")

        resizing_thread = threading.Thread(target=resizing_thread_function,
                                           daemon=True)
        resizing_thread.start()

        page = 0
        superglobals.state = "fileread"
        contents = []
        with open(file_path, "r") as file:
            contents = file.readlines()

        display_contents = contents
        for i in range(page * max_y, (page + 1) * max_y):
            if screenfunctions.indexists(display_contents, i):
                if len(display_contents[i]) > max_x - 44:
                    display_contents.insert(i + 1,
                                            display_contents[i][max_x - 45:])
                    display_contents[i] = display_contents[i][:max_x - 45]

        curses.curs_set(False)
        k = 0
        while k != ord('q'):
            #try:
            max_y = stdscr.getmaxyx()[0] - 1
            max_x = stdscr.getmaxyx()[1] - 1

            if max_y >= 39 and max_x >= 159:
                if superglobals.information_enabled_setting:
                    superglobals.information_enabled = True

                stdscr.erase()

                screenfunctions.render_defaults(stdscr)

                contents = []
                with open(file_path, "r") as file:
                    contents = file.readlines()

                display_contents = contents
                for i, _ in enumerate(display_contents):
                    if screenfunctions.indexists(display_contents, i):
                        if len(display_contents[i]) > max_x - 44:
                            display_contents.insert(
                                i + 1, display_contents[i][max_x - 45:])
                            display_contents[i] = display_contents[i][:max_x -
                                                                      45]

                for index, line_num in enumerate(
                        range(page * max_y, (page + 1) * max_y)):
                    if screenfunctions.indexists(display_contents, line_num):
                        stdscr.addstr(index, 44, display_contents[line_num])

                stdscr.attron(curses.A_REVERSE)
                stdscr.addstr(
                    max_y, 44,
                    "Press 'q' to exit, ARROW KEYS to change pages." + " " *
                    (max_x - 90))
                stdscr.addstr(max_y, max_x - 9, f"Page: {page}")
                stdscr.attroff(curses.A_REVERSE)

                k = stdscr.getch()

                if k == ord('q'):
                    break

                if k == curses.KEY_RIGHT and page < 255:
                    page += 1

                if k == curses.KEY_LEFT and page > 0:
                    page -= 1

            if max_y < 39 or max_x < 159:
                superglobals.information_enabled = False
                stdscr.addstr(
                    0, 0, "Py-Shell requires atleast a 160x40 window size.")
                stdscr.getch()
                stdscr.erase()
Esempio n. 6
0
def main(stdscr, cmds):

    curses.curs_set(False)

    page = 0

    cmds = [cmd.lower() for cmd in cmds]

    max_y = stdscr.getmaxyx()[0] - 1
    max_x = stdscr.getmaxyx()[1] - 1

    def resizing_thread_function():
        while True:
            if max_y < 39 or max_x < 159:
                print("\x1b[8;40;160t")



    resizing_thread = threading.Thread(target=resizing_thread_function,
    daemon=True)
    resizing_thread.start()

    k = 0
    while k != ord('q'):

        max_y = stdscr.getmaxyx()[0] - 1
        max_x = stdscr.getmaxyx()[1] - 1

        if max_y >= 39 and max_x >= 159:

            if superglobals.information_enabled_setting:
                superglobals.information_enabled = True

            stdscr.erase()

            screenfunctions.render_defaults(stdscr)

            if k == curses.KEY_RIGHT and page < 255:
                page += 1
            if k == curses.KEY_LEFT and page > 0:
                page -= 1

            if screenfunctions.indexists(cmds, 1):
                if cmds[1] == "stopwatch":
                    if page == 0:
                        stdscr.addstr(0, 45, "Help Menu for \"stopwatch\" command")

                        stdscr.addstr(2, 45, "stopwatch : Commands for a counter that can be viewed with the \"time\" command.")
                        stdscr.addstr(3, 45, "The created stopwatch shows the amount of time since it was created.")

                        stdscr.addstr(5, 45, "List of Commands and Usages:")
                        stdscr.addstr(6, 45, "  del; [index] : Deletes the stopwatch at [index]")
                        stdscr.addstr(7, 45, "  new; [name, optional] : Creates a new stopwatch that has the name [name]. If [name] is blank,")
                        stdscr.addstr(8, 45, "  it will set it to \"stopwatch [index + 1]\"")
                        stdscr.addstr(9, 45, "  reset; [index] : Resets the stopwatch at [index]")

                if cmds[1] == "timer":
                    if page == 0:
                        stdscr.addstr(0, 45, "Help Menu for \"timer\" command")

                        stdscr.addstr(2, 45, "timer : Commands for a counter that can be viewed with the \"time\" command.")
                        stdscr.addstr(3, 45, "The created timer shows the amount of time between now and a set amount of minutes after creation.")

                        stdscr.addstr(5, 45, "List of Commands and Usages:")
                        stdscr.addstr(6, 45, "  del; [index] : Deletes the timer at [index]")
                        stdscr.addstr(7, 45, "  new; [minutes]; [name, optional] : Creates a new timer that counts to [minutes] after creation,")
                        stdscr.addstr(8, 45, "  and has the name [name]. If [name] is blank, it will set it to \"timer [index + 1]\"")
                        stdscr.addstr(9, 45, "  reset; [index] : Resets the timer at [index]")

                if cmds[1] == "countdown":
                    if page == 0:
                        stdscr.addstr(0, 45, "Help Menu for \"contdown\" command")

                        stdscr.addstr(2, 45, "countdown : Commands for a counter that counts to a hour and minute that can be viewed with the \"time\" command.")
                        stdscr.addstr(3, 45, "The created countdown counts down to a given hour and minute.")

                        stdscr.addstr(5, 45, "List of Commands and Usages:")
                        stdscr.addstr(6, 45, "  del; [index] : Deletes the countdown at [index]")
                        stdscr.addstr(7, 45, "  new; [hour]; [minute]; [name, optional] : Creates a new countdown that counts down to the")
                        stdscr.addstr(8, 45, "  [minute]th minute of [hour] has the name [name]. If [name] is blank, it will set it to \"countdown [index + 1]\"")

                if cmds[1] == "calc":
                    if page == 0:
                        stdscr.addstr(0, 45, "Help Menu for \"calc\" command")

                        stdscr.addstr(2, 45, "calc : Basic calculator for general use.")

                        
                        stdscr.addstr(5, 45, "List of Commands and Usages:")
                        stdscr.addstr(6, 45, "  [x] : Sets the current number to [x].")
                        stdscr.addstr(7, 45, "  add; [x] : Adds [x] to the current number.")
                        stdscr.addstr(8, 45, "  sub; [x] : Subtracts [x] from the current number.")
                        stdscr.addstr(9, 45, "  mul; [x] : Multiplies the current number by [x].")
                        stdscr.addstr(10, 45, "  div; [x] : Divides the current number by [x].")
                        stdscr.addstr(11, 45, "  pow; [x] : Exponentiates the current number by [x]")
                        stdscr.addstr(12, 45, "  root; [x] : Sets the current number to the [x]th root of the current number.")
                        stdscr.addstr(13, 45, "  log : Sets the current number to the natural log of the current number.")
                        stdscr.addstr(14, 45, "  log2 : Sets the current number to the log2 of the current number.")
                        stdscr.addstr(15, 45, "  log10 : Sets the current number to the log10 of the current number.")

                if cmds[1] == "time":
                    if page == 0:
                        stdscr.addstr(0, 45, "Help Menu for \"time\" command")

                        stdscr.addstr(2, 45, "time : A menu displaying a variety of information about the time.")

                        stdscr.attron(curses.A_BOLD)
                        stdscr.addstr(5, 45, "Time does not have any commands")
                        stdscr.attroff(curses.A_BOLD)
                        
                        stdscr.addstr(7, 45, "The \"time\" menu has 4 panels.")
                        
                        stdscr.addstr(9, 45, "The first panel displays general information, such as the current date.")

                        stdscr.addstr(11, 45, "The second panel displays current stopwatches.")

                        stdscr.addstr(11, 45, "The third panel displays current timers.")
                        
                        stdscr.addstr(13, 45, "The fourth and final panel displays current countdowns.")

            if not screenfunctions.indexists(cmds, 1):
                if page == 0:
                    stdscr.addstr(0, 45, "Welcome to the Help Menu")
                    stdscr.addstr(1, 45, "You can type \"help; [command]\" to find sub-commands for a command.")
                    stdscr.addstr(2, 45, "If nothing appears, it means there are no sub-commands for that command.")

                    stdscr.addstr(4, 45, "Basic Syntax: The basic syntax cmd; option1; option2")

                    stdscr.addstr(6, 45, "List of Commands and Usages:")
                    #a
                    #b
                    #c
                    stdscr.addstr(7, 45, "  calc : Starts the calculator.")
                    stdscr.addstr(8, 45, "  color; [col] : Changes the text color (0-255).")
                    stdscr.addstr(9, 45, "  countdown; [cmd]; {options} : Uses the countdown command, see \"help; countdown\" for more details.")
                    #d
                    #e
                    #f
                    #g
                    #h
                    stdscr.addstr(10, 45, "  help; [cmd] : Shows help about [cmd], if no [cmd] is entered, it shows this screen.")
                    #i
                    stdscr.addstr(11, 45, "  information : Toggles the top left information.")
                    #j
                    #k
                    #l
                    #m
                    #n
                    #o
                    #p
                    #q
                    stdscr.addstr(12, 45, "  quit : Quits PyShell.")
                    #r
                    #s
                    stdscr.addstr(13, 45, "  stopwatch; [cmd]; {options} : Uses the stopwatch command, see \"help; stopwatch\" for more details.")
                    #t
                    stdscr.addstr(9, 45, "  time : Opens the time menu.")
                    stdscr.addstr(9, 45, "  timer; [cmd]; {options} : Uses the timer command, see \"help; timer\" for more details.")
                    #u
                    #v
                    #w
                    #x
                    #y
                    #z
            stdscr.attron(curses.A_REVERSE)
            stdscr.addstr(max_y, 45, "Press 'q' to exit, ARROW KEYS to change pages." + " " * (max_x - 91))
            stdscr.addstr(max_y, max_x - 9, f"Page: {page}")
            stdscr.attroff(curses.A_REVERSE)

            k = stdscr.getch()
        
        if max_y < 39 or max_x < 159:
            superglobals.information_enabled = False
            stdscr.addstr(0, 0, "Py-Shell requires atleast a 160x40 window size.")
            stdscr.getch()                                                      
            stdscr.erase()
    
    curses.echo()
    curses.curs_set(True)
Esempio n. 7
0
def main(stdscr):

    max_y = stdscr.getmaxyx()[0] - 1
    max_x = stdscr.getmaxyx()[1] - 1

    def resizing_thread_function():
        while True:
            if max_y < 39 or max_x < 159:
                print("\x1b[8;40;160t")

    resizing_thread = threading.Thread(target=resizing_thread_function,
                                       daemon=True)
    resizing_thread.start()

    num = decimal.Decimal(superglobals.last_calc_num)

    input_string = ""
    while True:
        try:

            max_y = stdscr.getmaxyx()[0] - 1
            max_x = stdscr.getmaxyx()[1] - 1

            if max_y >= 39 and max_x >= 159:

                if superglobals.information_enabled_setting:
                    superglobals.information_enabled = True

                stdscr.erase()

                screenfunctions.render_defaults(stdscr)

                stdscr.addstr(1, 45, str(num))

                screenfunctions.draw_box(stdscr, 0, 44, 2, max_x - 44, 1)
                screenfunctions.draw_box(stdscr, 3, 44, 7, max_x - 44, 1)
                stdscr.addstr(4, 45, "add; [x]")
                stdscr.addstr(5, 45, "sub; [x]")
                stdscr.addstr(6, 45, "mul; [x]")
                stdscr.addstr(7, 45, "div; [x]")
                stdscr.addstr(8, 45, "pow; [x]")
                stdscr.addstr(9, 45, "root; [x]")

                stdscr.addstr(4, 59, "log")
                stdscr.addstr(5, 59, "log2")
                stdscr.addstr(6, 59, "log10")

                input_string = screenfunctions.curses_input(
                    stdscr, int(max_y / 2), 0, f"{superglobals.state}:: ",
                    42 - len(superglobals.state) - 3)

                cmds = input_string.split("; ")
                cmds[0] = cmds[0].lower()

                for i, cmd in enumerate(cmds):
                    if i != 0:
                        if cmds[i] == "pi":
                            cmds[i] = "3.141592653"
                        if cmds[i] == "tau":
                            cmds[i] = "6.283185307"
                        if cmds[i] == "phi":
                            cmds[i] = "1.618033988"
                        if cmds[i] == "e":
                            cmds[i] = "2.718281828"

                if cmds[0] == "exit":
                    superglobals.last_calc_num = num
                    return
                if cmds[0] == "quit":
                    sys.exit(0)
                if screenfunctions.is_float(cmds[0]):
                    num = decimal.Decimal(cmds[0])
                if cmds[0] == "log" and num > 0:
                    num = decimal.Decimal(math.log(num))
                if cmds[0] == "log2" and num > 0:
                    num = decimal.Decimal(math.log2(num))
                if cmds[0] == "log10" and num > 0:
                    num = decimal.Decimal(math.log10(num))
                if screenfunctions.indexists(cmds, 1):
                    if cmds[0] == "add":
                        num += decimal.Decimal(cmds[1])
                    if cmds[0] == "sub":
                        num -= decimal.Decimal(cmds[1])
                    if cmds[0] == "mul":
                        num *= decimal.Decimal(cmds[1])
                    if cmds[0] == "div" and cmds[1] != "0":
                        num /= decimal.Decimal(cmds[1])
                    if cmds[0] == "pow":
                        num **= decimal.Decimal(cmds[1])
                    if cmds[0] == "root" and num > 0:
                        num **= decimal.Decimal(1 / decimal.Decimal(cmds[1]))

            if max_y < 39 or max_x < 159:
                superglobals.information_enabled = False
                stdscr.addstr(
                    0, 0, "Py-Shell requires atleast a 160x40 window size.")
                stdscr.getch()
                stdscr.erase()

        except Exception as e:
            superglobals.error_list.append(e)