Skip to content

Commit

Permalink
Terminal: Catch change directory signal in node-pty, rename terminal …
Browse files Browse the repository at this point in the history
…buffer and change Emacs default-directory variable real-time
  • Loading branch information
HollowMan6 committed Jul 3, 2020
1 parent 2013e0a commit e3e0cc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/terminal/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module
QTimer.singleShot(250, self.focus_terminal)

self.build_all_methods(self)

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

def focus_terminal(self):
event = QMouseEvent(QEvent.MouseButtonPress, QPointF(0, 0), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
Expand All @@ -76,10 +80,12 @@ def open_terminal_page(self):
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"])
self.buffer_widget.setHtml(html)

def on_change_directory(self):
self.update_title()
self.eval_in_emacs.emit('''(setq command-line-default-directory "'''+self.buffer_widget.execute_js("title")+'''")''')

def update_title(self):
# FIXME: rename title based on pwd
# self.change_title("")
pass
self.change_title(self.buffer_widget.execute_js("title"))

def destroy_buffer(self):
os.kill(self.background_process.pid, signal.SIGKILL)
Expand Down
11 changes: 10 additions & 1 deletion app/terminal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
cursorBlink: true,
theme: theme
});

var title = "~/"

const searchAddon = new SearchAddon.SearchAddon();

function get_selection() {
Expand Down Expand Up @@ -123,7 +126,13 @@
}

socket.onmessage = (msg) => {
if(msg==="Closing"){
var re = /:([^\x07]*?)\x07/g;
arr = re.exec(msg.data)
if(arr) {
title = arr[1]+"/";
}

if(msg==="Closing") {
socket.close();
}
}
Expand Down

0 comments on commit e3e0cc9

Please sign in to comment.