Skip to content

Commit

Permalink
fix #37 & #38 and a small tweak
Browse files Browse the repository at this point in the history
I am gotta leave now, here you go @Moosems
  • Loading branch information
littlewhitecloud authored Jun 19, 2023
1 parent 55f90b8 commit 771ff1a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tktermwidget/tkterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
from os import getcwd
from pathlib import Path
from platform import system
from subprocess import PIPE, Popen
from tkinter import Event, Misc, Text
from tkinter.ttk import Frame, Scrollbar
from subprocess import PIPE, Popen, CREATE_NEW_CONSOLE

from platformdirs import user_cache_dir

# Set constants
HISTORY_PATH = Path(user_cache_dir("tktermwidget"))
SYSTEM = system()
CREATE_NEW_CONSOLE = 0
SIGN = "$ "
if SYSTEM == "Windows":
from subprocess import CREATE_NEW_CONSOLE
SIGN = ">"
else:
CREATE_NEW_CONSOLE = 0
SIGN = "$ "

# Check that the history directory exists
if not HISTORY_PATH.exists():
Expand Down Expand Up @@ -66,7 +66,7 @@ class Terminal(Frame):
kill (Event) -> str: Kills the current command
loop (Event) -> str: Runs the command typed"""

def __init__(self, master: Misc, autohide: bool = False, *args, **kwargs):
def __init__(self, master: Misc, filehistory: str = None, autohide: bool = False, *args, **kwargs):
Frame.__init__(self, master)

# Set row and column weights
Expand Down Expand Up @@ -122,7 +122,8 @@ def __init__(self, master: Misc, autohide: bool = False, *args, **kwargs):
self.text.bind("<Control-KeyPress-c>", self.kill, add=True) # Isn't working

# History recorder
self.history = open(HISTORY_PATH / "history.txt", "r+", encoding="utf-8")
self.history = open(HISTORY_PATH / "history.txt" if not filehistory else filehistory, "r+", encoding="utf-8")

self.historys = [i.strip() for i in self.history.readlines() if i.strip()]
self.historyindex = len(self.historys) - 1

Expand Down Expand Up @@ -200,6 +201,8 @@ def loop(self, _: Event) -> str:
self.updates(None)
self.latest = self.text.index("insert")
return "break"
elif cmd == "exit":
self.master.quit()

if cmd.endswith(self.longsymbol):
self.longcmd += cmd.split(self.longsymbol)[0]
Expand Down

0 comments on commit 771ff1a

Please sign in to comment.