Terminal: Rename buffer when running programme as in #331

Signed-off-by: Hollow Man <hollowman186@vip.qq.com>
master
Hollow Man 6 years ago
parent 45e2fd9713
commit 3670485bd7
No known key found for this signature in database
GPG Key ID: 6CA2A0660F48F7A
  1. 18
      app/terminal/buffer.py
  2. 32
      app/terminal/index.html

@ -43,6 +43,7 @@ class AppBuffer(BrowserBuffer):
self.command = arguments_dict["command"]
self.start_directory = arguments_dict["directory"]
self.current_directory = self.start_directory
self.executing_command = ""
self.index_file = os.path.join(os.path.dirname(__file__), "index.html")
self.server_js = os.path.join(os.path.dirname(__file__), "server.js")
@ -83,10 +84,21 @@ class AppBuffer(BrowserBuffer):
def checking_status(self):
changed_directory = str(self.buffer_widget.execute_js("title"))
if not changed_directory == self.current_directory:
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 changed_executing_command != "":
self.change_title(changed_executing_command)
self.executing_command = changed_executing_command
elif changed_executing_command == "" and self.executing_command != "" or not changed_directory == self.current_directory:
self.change_title(changed_directory)
self.eval_in_emacs.emit('''(setq default-directory "'''+ changed_directory +'''")''')
self.current_directory = changed_directory
if not changed_directory == self.current_directory:
self.eval_in_emacs.emit('''(setq default-directory "'''+ changed_directory +'''")''')
self.current_directory = changed_directory
if self.executing_command != "":
self.executing_command = ""
if subprocess.Popen.poll(self.background_process) is not None:
self.destroy_buffer()

@ -37,7 +37,7 @@
var socket = new WebSocket("ws://127.0.0.1:%1");
}
catch(err) {
setTimeout('location.reload();',1000);
location.reload();
}
const term = new Terminal({
fontSize: "%4",
@ -46,6 +46,7 @@
});
var title = "%5"
var executing_command = ""
const searchAddon = new SearchAddon.SearchAddon();
@ -124,6 +125,34 @@
window.addEventListener("resize", sendSizeToServer);
term.onLineFeed(() => {
const buffer = term.buffer;
const new_line = buffer.getLine(buffer.baseY + buffer.cursorY);
if (new_line && !new_line.isWrapped) {
var input_data = get_line_data(buffer, buffer.baseY + buffer.cursorY - 1);
if (input_data.indexOf('$')!=-1){
executing_command = input_data.slice(input_data.indexOf('$')+1).trim()
if(executing_command.startsWith("cd ")) {
executing_command = ""
}
}
}
})
function get_line_data(buffer, line_index) {
let line = buffer.getLine(line_index);
if (!line) {
return;
}
let line_data = line.translateToString(true);
while (line_index > 0 && line.isWrapped) {
line = buffer.getLine(--line_index);
if (!line) {
break;
}
line_data = line.translateToString(false) + line_data;
}
return line_data;
}
}
socket.onmessage = (msg) => {
@ -131,6 +160,7 @@
arr = re.exec(msg.data)
if(arr) {
title = arr[1];
executing_command = ""
}
}

Loading…
Cancel
Save