diff --git a/app/terminal/buffer.py b/app/terminal/buffer.py index f5fb1d1..f22722e 100644 --- a/app/terminal/buffer.py +++ b/app/terminal/buffer.py @@ -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() diff --git a/app/terminal/index.html b/app/terminal/index.html index 54a27fe..ba637e7 100644 --- a/app/terminal/index.html +++ b/app/terminal/index.html @@ -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 = "" } }