From: Michael D. Lowis Date: Thu, 20 Jul 2017 01:12:33 +0000 (-0400) Subject: added escape code for updating working directory from shell X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=9325209b7abbbeb3f1186d0ca9be3b49e2341249;p=projs%2Ftide.git added escape code for updating working directory from shell --- diff --git a/lib/pty.c b/lib/pty.c index ad95b4e..fd1a532 100644 --- a/lib/pty.c +++ b/lib/pty.c @@ -86,17 +86,29 @@ void pty_send_rune(Rune rune) { } } +static void read_escape(char* data, long* i, long n) { + /* only one escape code supported and that is to change the working dir */ + if (data[*i] != 'P') return; + size_t sz = strlen(&data[*i + 1]); + chdir(&data[*i + 1]); + *i = *i + 1 + sz; +} + static void update(int fd, void* data) { /* Read from command if we have one */ long n = 0, i = 0; static char cmdbuf[8192]; - if ((n = read(PtyFD, cmdbuf, sizeof(cmdbuf))) < 0) + if ((n = read(PtyFD, cmdbuf, sizeof(cmdbuf)-1)) < 0) PtyFD = -1; + cmdbuf[n] = '\0'; while (i < n) { Rune rune = 0; size_t length = 0; while (!utf8decode(&rune, &length, cmdbuf[i++])); - view_insert(win_view(EDIT), false, rune); + if (rune == '\033') + read_escape(cmdbuf, &i, n); + else + view_insert(win_view(EDIT), false, rune); } win_buf(EDIT)->outpoint = win_view(EDIT)->selection.end; }