comparison src/terminal.c @ 29792:f661bbf74a6d v9.0.0235

patch 9.0.0235: 'autoshelldir' does not work with chunked respose Commit: https://github.com/vim/vim/commit/474ad390ccb8bbeb53848122829e04c52f0349ce Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 21 11:37:17 2022 +0100 patch 9.0.0235: 'autoshelldir' does not work with chunked respose Problem: 'autoshelldir' does not work with chunked respose. Solution: Collect chunks before parsing OSC 7. (closes https://github.com/vim/vim/issues/10949)
author Bram Moolenaar <Bram@vim.org>
date Sun, 21 Aug 2022 12:45:03 +0200
parents 89e1d67814a9
children 86eb4aba16c3
comparison
equal deleted inserted replaced
29791:069316b0c18c 29792:f661bbf74a6d
4475 * "\033]7;file://HOSTNAME/CURRENT/DIR\033\\" 4475 * "\033]7;file://HOSTNAME/CURRENT/DIR\033\\"
4476 * and what VTerm provides via VTermStringFragment is 4476 * and what VTerm provides via VTermStringFragment is
4477 * "file://HOSTNAME/CURRENT/DIR" 4477 * "file://HOSTNAME/CURRENT/DIR"
4478 */ 4478 */
4479 static void 4479 static void
4480 sync_shell_dir(VTermStringFragment *frag) 4480 sync_shell_dir(garray_T *gap)
4481 { 4481 {
4482 int offset = 7; // len of "file://" is 7 4482 int offset = 7; // len of "file://" is 7
4483 char *pos = (char *)frag->str + offset; 4483 char *pos = (char *)gap->ga_data + offset;
4484 char_u *new_dir; 4484 char_u *new_dir;
4485 4485
4486 // remove HOSTNAME to get PWD 4486 // remove HOSTNAME to get PWD
4487 while (*pos != '/' && offset < (int)frag->len) 4487 while (offset < (int)gap->ga_len && *pos != '/' )
4488 { 4488 {
4489 offset += 1; 4489 ++offset;
4490 pos += 1; 4490 ++pos;
4491 } 4491 }
4492 4492
4493 if (offset >= (int)frag->len) 4493 if (offset >= (int)gap->ga_len)
4494 { 4494 {
4495 semsg(_(e_failed_to_extract_pwd_from_str_check_your_shell_config), 4495 semsg(_(e_failed_to_extract_pwd_from_str_check_your_shell_config),
4496 frag->str); 4496 gap->ga_data);
4497 return; 4497 return;
4498 } 4498 }
4499 4499
4500 new_dir = alloc(frag->len - offset + 1); 4500 new_dir = alloc(gap->ga_len - offset + 1);
4501 url_decode(pos, frag->len-offset, new_dir); 4501 url_decode(pos, gap->ga_len-offset, new_dir);
4502 changedir_func(new_dir, TRUE, CDSCOPE_WINDOW); 4502 changedir_func(new_dir, TRUE, CDSCOPE_WINDOW);
4503 vim_free(new_dir); 4503 vim_free(new_dir);
4504 } 4504 }
4505 4505
4506 /* 4506 /*
4516 channel_T *channel = term->tl_job == NULL ? NULL 4516 channel_T *channel = term->tl_job == NULL ? NULL
4517 : term->tl_job->jv_channel; 4517 : term->tl_job->jv_channel;
4518 garray_T *gap = &term->tl_osc_buf; 4518 garray_T *gap = &term->tl_osc_buf;
4519 4519
4520 // We recognize only OSC 5 1 ; {command} and OSC 7 ; {command} 4520 // We recognize only OSC 5 1 ; {command} and OSC 7 ; {command}
4521 if (p_asd && command == 7) 4521 if (command != 51 && (command != 7 || !p_asd))
4522 {
4523 sync_shell_dir(&frag);
4524 return 1;
4525 }
4526
4527 if (command != 51)
4528 return 0; 4522 return 0;
4529 4523
4530 // Concatenate what was received until the final piece is found. 4524 // Concatenate what was received until the final piece is found.
4531 if (ga_grow(gap, (int)frag.len + 1) == FAIL) 4525 if (ga_grow(gap, (int)frag.len + 1) == FAIL)
4532 { 4526 {
4537 gap->ga_len += (int)frag.len; 4531 gap->ga_len += (int)frag.len;
4538 if (!frag.final) 4532 if (!frag.final)
4539 return 1; 4533 return 1;
4540 4534
4541 ((char *)gap->ga_data)[gap->ga_len] = 0; 4535 ((char *)gap->ga_data)[gap->ga_len] = 0;
4536
4537 if (command == 7)
4538 {
4539 sync_shell_dir(gap);
4540 ga_clear(gap);
4541 return 1;
4542 }
4543
4542 reader.js_buf = gap->ga_data; 4544 reader.js_buf = gap->ga_data;
4543 reader.js_fill = NULL; 4545 reader.js_fill = NULL;
4544 reader.js_used = 0; 4546 reader.js_used = 0;
4545 if (json_decode(&reader, &tv, 0) == OK 4547 if (json_decode(&reader, &tv, 0) == OK
4546 && tv.v_type == VAR_LIST 4548 && tv.v_type == VAR_LIST