aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Fürmetz <fuermetz@mailbox.org>2017-07-26 15:44:07 +0200
committerLukas Fürmetz <fuermetz@mailbox.org>2017-07-26 15:44:07 +0200
commitd4c3ee244ce020a7e7a032f6989bdc4c5e428235 (patch)
treef8dd9c45595b8a42993178705fc9ee9467a89c24
parente164ae7313e78c2ab31d4496a801ac0ec4d50535 (diff)
Handle exit of shell
-rw-r--r--vterm-module.c12
-rw-r--r--vterm-module.h1
-rw-r--r--vterm.el4
3 files changed, 14 insertions, 3 deletions
diff --git a/vterm-module.c b/vterm-module.c
index 32f7526..b7a0e01 100644
--- a/vterm-module.c
+++ b/vterm-module.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
#include <vterm.h>
@@ -273,11 +274,11 @@ static emacs_value Fvterm_new(emacs_env *env, ptrdiff_t nargs,
termios.c_cc[VMIN] = 1;
termios.c_cc[VTIME] = 0;
- pid_t pid = forkpty(&term->masterfd, NULL, &termios, &size);
+ term->pid = forkpty(&term->masterfd, NULL, &termios, &size);
fcntl(term->masterfd, F_SETFL, fcntl(term->masterfd, F_GETFL) | O_NONBLOCK);
- if (pid == 0) {
+ if (term->pid == 0) {
setenv("TERM", "xterm", 1);
char *shell = getenv("SHELL");
char *args[2] = {shell, NULL};
@@ -313,6 +314,13 @@ static void process_key(struct Term *term, char *key, VTermModifier modifier) {
static emacs_value Fvterm_update(emacs_env *env, ptrdiff_t nargs,
emacs_value args[], void *data) {
struct Term *term = env->get_user_ptr(env, args[0]);
+
+ // Check if exited
+ int status;
+ if (waitpid(term->pid, &status, WNOHANG) > 0) {
+ return env->intern(env, "nil");
+ }
+
// Process keys
if (nargs > 1) {
ptrdiff_t len = string_bytes(env, args[1]);
diff --git a/vterm-module.h b/vterm-module.h
index 808d48c..3ebefe5 100644
--- a/vterm-module.h
+++ b/vterm-module.h
@@ -6,6 +6,7 @@ int plugin_is_GPL_compatible;
struct Term {
VTerm *vt;
int masterfd;
+ pid_t pid;
};
static void bind_function(emacs_env *env, const char *name, emacs_value Sfun);
diff --git a/vterm.el b/vterm.el
index e564f65..c28af20 100644
--- a/vterm.el
+++ b/vterm.el
@@ -62,7 +62,9 @@ be send to the terminal.")
(let ((inhibit-redisplay t)
(inhibit-read-only t))
(with-current-buffer buffer
- (vterm-update vterm-term))))
+ (unless (vterm-update vterm-term)
+ (cancel-timer vterm-timer)
+ (insert "\nProcess exited!\n\n")))))
(defun vterm-kill-buffer-hook ()
(when (eq major-mode 'vterm-mode)