Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal: Rewrite #324, add support for indicating ssh and program running in terminal buffer name #325 #331

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 31 additions & 11 deletions app/terminal/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import subprocess
import signal
import threading
import socket
import getpass
import json

Expand All @@ -45,7 +46,9 @@ def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module
self.current_directory = self.start_directory
self.index_file = os.path.join(os.path.dirname(__file__), "index.html")
self.server_js = os.path.join(os.path.dirname(__file__), "server.js")

self.host_destination = str(getpass.getuser())+"@"+str(socket.gethostname())
self.current_destination = self.host_destination
self.executing_command = ""
self.buffer_widget.titleChanged.connect(self.change_title)

# Start server process.
Expand All @@ -65,7 +68,7 @@ def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module

self.timer=QTimer()
self.timer.start(250)
self.timer.timeout.connect(self.on_change_directory)
self.timer.timeout.connect(self.update_title)

def focus_terminal(self):
event = QMouseEvent(QEvent.MouseButtonPress, QPointF(0, 0), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
Expand All @@ -78,18 +81,35 @@ def open_terminal_page(self):
(self.emacs_var_dict["eaf-terminal-dark-mode"] == "" and self.emacs_var_dict["eaf-emacs-theme-mode"] == "dark"):
theme = "dark"
with open(self.index_file, "r") as f:
html = f.read().replace("%1", str(self.port)).replace("%2", "file://" + os.path.join(os.path.dirname(__file__))).replace("%3", theme).replace("%4", self.emacs_var_dict["eaf-terminal-font-size"]).replace("%5", self.current_directory)
html = f.read().replace("%1", str(self.port)).replace("%2", "file://" + os.path.join(os.path.dirname(__file__))).replace("%3", theme).replace("%4", self.emacs_var_dict["eaf-terminal-font-size"]).replace("%5", self.current_directory).replace("%6", self.host_destination)
self.buffer_widget.setHtml(html)

def on_change_directory(self):
changed_directory = self.buffer_widget.execute_js("title")
if not str(changed_directory) == self.current_directory:
self.update_title()
self.eval_in_emacs.emit('''(setq default-directory "'''+ str(changed_directory) +'''")''')
self.current_directory = str(changed_directory)

def update_title(self):
self.change_title(self.buffer_widget.execute_js("title"))
changed_directory = str(self.buffer_widget.execute_js("current_directory"))
changed_destination = str(self.buffer_widget.execute_js("current_destination"))
changed_executing_command = str(self.buffer_widget.execute_js("executing_command"))
if len(changed_executing_command) > 30:
changed_executing_command = changed_executing_command[:30]
if changed_executing_command != self.executing_command and self.executing_command == "":
self.change_title(changed_executing_command)
else:
if not changed_directory == self.current_directory or changed_executing_command != self.executing_command:
if changed_destination == self.host_destination:
self.change_title(changed_directory)
self.eval_in_emacs.emit('''(setq default-directory "'''+ changed_directory +'''")''')
else:
self.change_title(changed_destination+ ":" +changed_directory)
else:
if not changed_destination == self.host_destination:
if not changed_destination == self.current_destination:
self.change_title(changed_destination+ ":" +changed_directory)
else:
if not changed_destination == self.current_destination:
self.change_title(changed_directory)
self.eval_in_emacs.emit('''(setq default-directory "'''+ changed_directory +'''")''')
self.executing_command = changed_executing_command
self.current_destination = changed_destination
self.current_directory = changed_directory

def destroy_buffer(self):
os.kill(self.background_process.pid, signal.SIGKILL)
Expand Down