Fix completion and save logs during session
This commit is contained in:
parent
0813b927b0
commit
d96910092b
@ -1,2 +1,2 @@
|
|||||||
__version__ = "3.4.3"
|
__version__ = "3.5.0"
|
||||||
|
|
||||||
|
@ -28,6 +28,25 @@ def _getallfolders(config):
|
|||||||
folders.extend(subfolders)
|
folders.extend(subfolders)
|
||||||
return folders
|
return folders
|
||||||
|
|
||||||
|
def _getcwd(words, option, folderonly=False):
|
||||||
|
# Expand tilde to home directory if present
|
||||||
|
if words[-1].startswith("~"):
|
||||||
|
words[-1] = os.path.expanduser(words[-1])
|
||||||
|
|
||||||
|
if words[-1] == option:
|
||||||
|
path = './*'
|
||||||
|
else:
|
||||||
|
path = words[-1] + "*"
|
||||||
|
|
||||||
|
pathstrings = glob.glob(path)
|
||||||
|
for i in range(len(pathstrings)):
|
||||||
|
if os.path.isdir(pathstrings[i]):
|
||||||
|
pathstrings[i] += '/'
|
||||||
|
pathstrings = [s[2:] if s.startswith('./') else s for s in pathstrings]
|
||||||
|
if folderonly:
|
||||||
|
pathstrings = [s for s in pathstrings if os.path.isdir(s)]
|
||||||
|
return pathstrings
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
home = os.path.expanduser("~")
|
home = os.path.expanduser("~")
|
||||||
defaultdir = home + '/.config/conn'
|
defaultdir = home + '/.config/conn'
|
||||||
@ -73,18 +92,11 @@ def main():
|
|||||||
if words[0] in ["--rm", "--del", "-r", "--mod", "--edit", "-e", "--show", "-s", "mv", "move", "cp", "copy"]:
|
if words[0] in ["--rm", "--del", "-r", "--mod", "--edit", "-e", "--show", "-s", "mv", "move", "cp", "copy"]:
|
||||||
strings.extend(nodes)
|
strings.extend(nodes)
|
||||||
if words[0] in ["run", "import", "export"]:
|
if words[0] in ["run", "import", "export"]:
|
||||||
if words[-1] in ["run", "import", "export"]:
|
|
||||||
path = './*'
|
|
||||||
else:
|
|
||||||
path = words[-1] + "*"
|
|
||||||
pathstrings = glob.glob(path)
|
|
||||||
for i in range(len(pathstrings)):
|
|
||||||
if os.path.isdir(pathstrings[i]):
|
|
||||||
pathstrings[i] += '/'
|
|
||||||
strings = ["--help"]
|
strings = ["--help"]
|
||||||
pathstrings = [s[2:] if s.startswith('./') else s for s in pathstrings]
|
|
||||||
if words[0] == "export":
|
if words[0] == "export":
|
||||||
pathstrings = [s for s in pathstrings if os.path.isdir(s)]
|
pathstrings = _getcwd(words, words[0], True)
|
||||||
|
else:
|
||||||
|
pathstrings = _getcwd(words, words[0])
|
||||||
strings.extend(pathstrings)
|
strings.extend(pathstrings)
|
||||||
if words[0] == "run":
|
if words[0] == "run":
|
||||||
strings.extend(nodes)
|
strings.extend(nodes)
|
||||||
@ -102,6 +114,8 @@ def main():
|
|||||||
strings=["bash", "zsh"]
|
strings=["bash", "zsh"]
|
||||||
if words[0] == "config" and words[1] in ["--fzf", "--allow-uppercase"]:
|
if words[0] == "config" and words[1] in ["--fzf", "--allow-uppercase"]:
|
||||||
strings=["true", "false"]
|
strings=["true", "false"]
|
||||||
|
if words[0] == "config" and words[1] in ["--configfolder"]:
|
||||||
|
strings=_getcwd(words,words[0],True)
|
||||||
|
|
||||||
|
|
||||||
if app == "bash":
|
if app == "bash":
|
||||||
|
@ -1184,8 +1184,13 @@ class connapp:
|
|||||||
_conn()
|
_conn()
|
||||||
{
|
{
|
||||||
mapfile -t strings < <(connpy-completion-helper "bash" "${#COMP_WORDS[@]}" "${COMP_WORDS[@]}")
|
mapfile -t strings < <(connpy-completion-helper "bash" "${#COMP_WORDS[@]}" "${COMP_WORDS[@]}")
|
||||||
local IFS=$'\\t\\n'
|
local IFS=$'\t\n'
|
||||||
COMPREPLY=($(compgen -W "$(printf '%s' "${strings[@]}")" -- "${COMP_WORDS[-1]}"))
|
local home_dir=$(eval echo ~)
|
||||||
|
local last_word=${COMP_WORDS[-1]/\~/$home_dir}
|
||||||
|
COMPREPLY=($(compgen -W "$(printf '%s' "${strings[@]}")" -- "$last_word"))
|
||||||
|
if [ "$last_word" != "${COMP_WORDS[-1]}" ]; then
|
||||||
|
COMPREPLY=(${COMPREPLY[@]/$home_dir/\~})
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -o nospace -o nosort -F _conn conn
|
complete -o nospace -o nosort -F _conn conn
|
||||||
@ -1198,14 +1203,20 @@ complete -o nospace -o nosort -F _conn connpy
|
|||||||
autoload -U compinit && compinit
|
autoload -U compinit && compinit
|
||||||
_conn()
|
_conn()
|
||||||
{
|
{
|
||||||
strings=($(connpy-completion-helper "zsh" ${#words} $words))
|
local home_dir=$(eval echo ~)
|
||||||
|
last_word=${words[-1]/\~/$home_dir}
|
||||||
|
strings=($(connpy-completion-helper "zsh" ${#words} $words[1,-2] $last_word))
|
||||||
for string in "${strings[@]}"; do
|
for string in "${strings[@]}"; do
|
||||||
|
#Replace the expanded home directory with ~
|
||||||
|
if [ "$last_word" != "$words[-1]" ]; then
|
||||||
|
string=${string/$home_dir/\~}
|
||||||
|
fi
|
||||||
if [[ "${string}" =~ .*/$ ]]; then
|
if [[ "${string}" =~ .*/$ ]]; then
|
||||||
# If the string ends with a '/', do not append a space
|
# If the string ends with a '/', do not append a space
|
||||||
compadd -S '' -- "$string"
|
compadd -Q -S '' -- "$string"
|
||||||
else
|
else
|
||||||
# If the string does not end with a '/', append a space
|
# If the string does not end with a '/', append a space
|
||||||
compadd -S ' ' -- "$string"
|
compadd -Q -S ' ' -- "$string"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -161,6 +161,21 @@ class node:
|
|||||||
else:
|
else:
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
def _savelog(self):
|
||||||
|
'''Save the log buffer to the file at regular intervals if there are changes.'''
|
||||||
|
t = threading.current_thread()
|
||||||
|
prev_size = 0 # Store the previous size of the buffer
|
||||||
|
|
||||||
|
while getattr(t, "do_run", True): # Check if thread is signaled to stop
|
||||||
|
current_size = self.mylog.tell() # Current size of the buffer
|
||||||
|
|
||||||
|
# Only save if the buffer size has changed
|
||||||
|
if current_size != prev_size:
|
||||||
|
with open(self.logfile, "w") as f: # Use "w" to overwrite the file
|
||||||
|
f.write(self._logclean(self.mylog.getvalue().decode(), True))
|
||||||
|
prev_size = current_size # Update the previous size
|
||||||
|
sleep(5)
|
||||||
|
|
||||||
def _filter(self, a):
|
def _filter(self, a):
|
||||||
#Set time for last input when using interact
|
#Set time for last input when using interact
|
||||||
self.lastinput = time()
|
self.lastinput = time()
|
||||||
@ -192,9 +207,15 @@ class node:
|
|||||||
self.child.setwinsize(int(size.group(2)),int(size.group(1)))
|
self.child.setwinsize(int(size.group(2)),int(size.group(1)))
|
||||||
print("Connected to " + self.unique + " at " + self.host + (":" if self.port != '' else '') + self.port + " via: " + self.protocol)
|
print("Connected to " + self.unique + " at " + self.host + (":" if self.port != '' else '') + self.port + " via: " + self.protocol)
|
||||||
if 'logfile' in dir(self):
|
if 'logfile' in dir(self):
|
||||||
|
# Initialize self.mylog
|
||||||
if not 'mylog' in dir(self):
|
if not 'mylog' in dir(self):
|
||||||
self.mylog = io.BytesIO()
|
self.mylog = io.BytesIO()
|
||||||
self.child.logfile_read = self.mylog
|
self.child.logfile_read = self.mylog
|
||||||
|
|
||||||
|
# Start the _savelog thread
|
||||||
|
log_thread = threading.Thread(target=self._savelog)
|
||||||
|
log_thread.daemon = True
|
||||||
|
log_thread.start()
|
||||||
if 'missingtext' in dir(self):
|
if 'missingtext' in dir(self):
|
||||||
print(self.child.after.decode(), end='')
|
print(self.child.after.decode(), end='')
|
||||||
if self.idletime > 0:
|
if self.idletime > 0:
|
||||||
@ -204,11 +225,9 @@ class node:
|
|||||||
if debug:
|
if debug:
|
||||||
print(self.mylog.getvalue().decode())
|
print(self.mylog.getvalue().decode())
|
||||||
self.child.interact(input_filter=self._filter)
|
self.child.interact(input_filter=self._filter)
|
||||||
if "logfile" in dir(self):
|
if 'logfile' in dir(self):
|
||||||
output = self._logclean(self.mylog.getvalue().decode(), True)
|
|
||||||
with open(self.logfile, "w") as f:
|
with open(self.logfile, "w") as f:
|
||||||
f.write(output)
|
f.write(self._logclean(self.mylog.getvalue().decode(), True))
|
||||||
f.close()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(connect)
|
print(connect)
|
||||||
|
@ -2973,8 +2973,13 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
_conn()
|
_conn()
|
||||||
{
|
{
|
||||||
mapfile -t strings < <(connpy-completion-helper "bash" "${#COMP_WORDS[@]}" "${COMP_WORDS[@]}")
|
mapfile -t strings < <(connpy-completion-helper "bash" "${#COMP_WORDS[@]}" "${COMP_WORDS[@]}")
|
||||||
local IFS=$'\\t\\n'
|
local IFS=$'\t\n'
|
||||||
COMPREPLY=($(compgen -W "$(printf '%s' "${strings[@]}")" -- "${COMP_WORDS[-1]}"))
|
local home_dir=$(eval echo ~)
|
||||||
|
local last_word=${COMP_WORDS[-1]/\~/$home_dir}
|
||||||
|
COMPREPLY=($(compgen -W "$(printf '%s' "${strings[@]}")" -- "$last_word"))
|
||||||
|
if [ "$last_word" != "${COMP_WORDS[-1]}" ]; then
|
||||||
|
COMPREPLY=(${COMPREPLY[@]/$home_dir/\~})
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -o nospace -o nosort -F _conn conn
|
complete -o nospace -o nosort -F _conn conn
|
||||||
@ -2987,14 +2992,20 @@ complete -o nospace -o nosort -F _conn connpy
|
|||||||
autoload -U compinit && compinit
|
autoload -U compinit && compinit
|
||||||
_conn()
|
_conn()
|
||||||
{
|
{
|
||||||
strings=($(connpy-completion-helper "zsh" ${#words} $words))
|
local home_dir=$(eval echo ~)
|
||||||
|
last_word=${words[-1]/\~/$home_dir}
|
||||||
|
strings=($(connpy-completion-helper "zsh" ${#words} $words[1,-2] $last_word))
|
||||||
for string in "${strings[@]}"; do
|
for string in "${strings[@]}"; do
|
||||||
|
#Replace the expanded home directory with ~
|
||||||
|
if [ "$last_word" != "$words[-1]" ]; then
|
||||||
|
string=${string/$home_dir/\~}
|
||||||
|
fi
|
||||||
if [[ "${string}" =~ .*/$ ]]; then
|
if [[ "${string}" =~ .*/$ ]]; then
|
||||||
# If the string ends with a '/', do not append a space
|
# If the string ends with a '/', do not append a space
|
||||||
compadd -S '' -- "$string"
|
compadd -Q -S '' -- "$string"
|
||||||
else
|
else
|
||||||
# If the string does not end with a '/', append a space
|
# If the string does not end with a '/', append a space
|
||||||
compadd -S ' ' -- "$string"
|
compadd -Q -S ' ' -- "$string"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -3461,6 +3472,21 @@ tasks:
|
|||||||
else:
|
else:
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
def _savelog(self):
|
||||||
|
'''Save the log buffer to the file at regular intervals if there are changes.'''
|
||||||
|
t = threading.current_thread()
|
||||||
|
prev_size = 0 # Store the previous size of the buffer
|
||||||
|
|
||||||
|
while getattr(t, "do_run", True): # Check if thread is signaled to stop
|
||||||
|
current_size = self.mylog.tell() # Current size of the buffer
|
||||||
|
|
||||||
|
# Only save if the buffer size has changed
|
||||||
|
if current_size != prev_size:
|
||||||
|
with open(self.logfile, "w") as f: # Use "w" to overwrite the file
|
||||||
|
f.write(self._logclean(self.mylog.getvalue().decode(), True))
|
||||||
|
prev_size = current_size # Update the previous size
|
||||||
|
sleep(5)
|
||||||
|
|
||||||
def _filter(self, a):
|
def _filter(self, a):
|
||||||
#Set time for last input when using interact
|
#Set time for last input when using interact
|
||||||
self.lastinput = time()
|
self.lastinput = time()
|
||||||
@ -3492,9 +3518,15 @@ tasks:
|
|||||||
self.child.setwinsize(int(size.group(2)),int(size.group(1)))
|
self.child.setwinsize(int(size.group(2)),int(size.group(1)))
|
||||||
print("Connected to " + self.unique + " at " + self.host + (":" if self.port != '' else '') + self.port + " via: " + self.protocol)
|
print("Connected to " + self.unique + " at " + self.host + (":" if self.port != '' else '') + self.port + " via: " + self.protocol)
|
||||||
if 'logfile' in dir(self):
|
if 'logfile' in dir(self):
|
||||||
|
# Initialize self.mylog
|
||||||
if not 'mylog' in dir(self):
|
if not 'mylog' in dir(self):
|
||||||
self.mylog = io.BytesIO()
|
self.mylog = io.BytesIO()
|
||||||
self.child.logfile_read = self.mylog
|
self.child.logfile_read = self.mylog
|
||||||
|
|
||||||
|
# Start the _savelog thread
|
||||||
|
log_thread = threading.Thread(target=self._savelog)
|
||||||
|
log_thread.daemon = True
|
||||||
|
log_thread.start()
|
||||||
if 'missingtext' in dir(self):
|
if 'missingtext' in dir(self):
|
||||||
print(self.child.after.decode(), end='')
|
print(self.child.after.decode(), end='')
|
||||||
if self.idletime > 0:
|
if self.idletime > 0:
|
||||||
@ -3504,11 +3536,9 @@ tasks:
|
|||||||
if debug:
|
if debug:
|
||||||
print(self.mylog.getvalue().decode())
|
print(self.mylog.getvalue().decode())
|
||||||
self.child.interact(input_filter=self._filter)
|
self.child.interact(input_filter=self._filter)
|
||||||
if "logfile" in dir(self):
|
if 'logfile' in dir(self):
|
||||||
output = self._logclean(self.mylog.getvalue().decode(), True)
|
|
||||||
with open(self.logfile, "w") as f:
|
with open(self.logfile, "w") as f:
|
||||||
f.write(output)
|
f.write(self._logclean(self.mylog.getvalue().decode(), True))
|
||||||
f.close()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(connect)
|
print(connect)
|
||||||
@ -3821,9 +3851,15 @@ tasks:
|
|||||||
self.child.setwinsize(int(size.group(2)),int(size.group(1)))
|
self.child.setwinsize(int(size.group(2)),int(size.group(1)))
|
||||||
print("Connected to " + self.unique + " at " + self.host + (":" if self.port != '' else '') + self.port + " via: " + self.protocol)
|
print("Connected to " + self.unique + " at " + self.host + (":" if self.port != '' else '') + self.port + " via: " + self.protocol)
|
||||||
if 'logfile' in dir(self):
|
if 'logfile' in dir(self):
|
||||||
|
# Initialize self.mylog
|
||||||
if not 'mylog' in dir(self):
|
if not 'mylog' in dir(self):
|
||||||
self.mylog = io.BytesIO()
|
self.mylog = io.BytesIO()
|
||||||
self.child.logfile_read = self.mylog
|
self.child.logfile_read = self.mylog
|
||||||
|
|
||||||
|
# Start the _savelog thread
|
||||||
|
log_thread = threading.Thread(target=self._savelog)
|
||||||
|
log_thread.daemon = True
|
||||||
|
log_thread.start()
|
||||||
if 'missingtext' in dir(self):
|
if 'missingtext' in dir(self):
|
||||||
print(self.child.after.decode(), end='')
|
print(self.child.after.decode(), end='')
|
||||||
if self.idletime > 0:
|
if self.idletime > 0:
|
||||||
@ -3833,11 +3869,9 @@ tasks:
|
|||||||
if debug:
|
if debug:
|
||||||
print(self.mylog.getvalue().decode())
|
print(self.mylog.getvalue().decode())
|
||||||
self.child.interact(input_filter=self._filter)
|
self.child.interact(input_filter=self._filter)
|
||||||
if "logfile" in dir(self):
|
if 'logfile' in dir(self):
|
||||||
output = self._logclean(self.mylog.getvalue().decode(), True)
|
|
||||||
with open(self.logfile, "w") as f:
|
with open(self.logfile, "w") as f:
|
||||||
f.write(output)
|
f.write(self._logclean(self.mylog.getvalue().decode(), True))
|
||||||
f.close()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(connect)
|
print(connect)
|
||||||
|
Loading…
Reference in New Issue
Block a user