Skip to content

Commit

Permalink
fix #35
Browse files Browse the repository at this point in the history
  • Loading branch information
littlewhitecloud authored Jul 12, 2023
1 parent 1f187c3 commit e38f1a4
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions tktermwidget/widgets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tkinter Terminal widget"""
from __future__ import annotations

from os import getcwd
from os import getcwd, chdir, path
from pathlib import Path
from platform import system
from subprocess import PIPE, Popen
Expand Down Expand Up @@ -179,7 +179,9 @@ def execute(self, _: Event) -> str:
cmd = self.text.get(f"{self.index}.0", "end-1c")
# Split the command from the line also strip
cmd = cmd.split(SIGN)[-1].strip()
self.index += 1 # if some "if" statement return "break"

# TODO: get rid off all return "break" in if statements
# use the flag leave: bool instead of

if cmd.endswith(self.longsymbol):
self.longcmd += cmd.split(self.longsymbol)[0]
Expand Down Expand Up @@ -209,6 +211,15 @@ def execute(self, _: Event) -> str:
return "break"
elif cmd == "exit":
self.master.quit()
elif cmd.startswith("cd"): # TAG: is all platform use cd...?
if cmd == "cd..":
chdir(path.abspath(path.join(getcwd(), "..")))
else:
chdir(cmd.split()[-1])
self.newline()
self.directory()
return "break"


# Set the insert position is at the end
self.text.mark_set("insert", f"{self.index}.end")
Expand All @@ -229,9 +240,9 @@ def execute(self, _: Event) -> str:
# The following needs to be put in an after so the kill command works

# Check if the command was successful
output: tuple = self.current_process.communicate()
returnlines: str = output[0]
errors: str = output[1]
returnlines: str = ""
errors: str = ""
returnlines, errors = self.current_process.communicate()
returncode = self.current_process.returncode
self.current_process = None

Expand All @@ -247,11 +258,15 @@ def execute(self, _: Event) -> str:
# Update the text and the index
self.index = int(self.text.index("insert").split(".")[0])
self.update()
print(self.index)

del returnlines, errors, returncode, cmd
return "break" # Prevent the default newline character insertion

def newline(self) -> None:
"""Insert a newline"""
self.text.insert("insert", "\n")
self.index += 1

def update(self) -> str:
"""Update the text widget or the command has no output"""
Expand Down

0 comments on commit e38f1a4

Please sign in to comment.