Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewing an issue/pr by GitHub CLI on :terminal, the fragments of the ANSI Escape code are put in prompt. #27572

Closed
kyoh86 opened this issue Feb 22, 2024 · 1 comment · Fixed by #27589
Labels
bug issues reporting wrong behavior events events, autocommands terminal built-in :terminal or :shell
Milestone

Comments

@kyoh86
Copy link

kyoh86 commented Feb 22, 2024

Problem

Using gh pr view or gh issue view to see pr/issue on :terminal, fragments of the ANSI Escape code (like 11;rgb:0000/0000/0000) are put in prompt.
(And gh [pr|issue] view was failed)

$ gh --repo neovim/neovim issue view 1
Fix build #1
Closed • ashleyh opened about 10 years ago • 1 comment


  I've just tweaked things until it builds (and the tests pass) on:                                                   
                                                                                                                      
  • my Arch desktop                                                                                                   
  • my OSX laptop                                                                                                     
  • a fresh Ubuntu 12.04 (LTS) container                                                                              
  • a fresh Ubuntu 13.10 container                                                                                    
                                                                                                                      
  There is some nonsense that means gettext has to be disabled on OSX for now.                                        


tarruda (Member) • Feb  1, 2014 • Newest comment

  I squashed and merged, thanks                                                                                       


View this issue on GitHub: https://github.com/neovim/neovim/pull/1
$ 11;rgb:0000/0000/0000
$ echo $?
1

Steps to reproduce

  1. Start naked Neovim nvim -u NONE
  2. Run Ex command in the Neovim :terminal
  3. View an issue or a pr like: gh --repo neovim/neovim issue view 1

Expected behavior

I expect that just an issue or a pr is shown.

Neovim version (nvim -v)

v0.10.0-dev-9bb046d

Vim (not Nvim) behaves the same?

no, vim 9.1

Operating system/version

Arch Linux

Terminal name/version

WezTerm

$TERM environment variable

xterm-256color

Installation

build from repo

@kyoh86 kyoh86 added the bug issues reporting wrong behavior label Feb 22, 2024
@zeertzjq zeertzjq added terminal built-in :terminal or :shell events events, autocommands labels Feb 22, 2024
@zeertzjq
Copy link
Member

zeertzjq commented Feb 22, 2024

Ref #22159 (comment)

There may be synchronization concerns, I think autocommands do not run immediately and there should probably be an autocommand queue which runs them eventually in event loop cycle. So guaranteeing the OSC output of an application reaches the underlying terminal in the right time may be hard.

An easy solution is to make TermRequest synchronous:

diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index a8f95cf44e..414a82f457 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -178,12 +178,8 @@ static VTermScreenCallbacks vterm_screen_callbacks = {
 
 static Set(ptr_t) invalidated_terminals = SET_INIT;
 
-static void emit_term_request(void **argv)
+static void emit_term_request(char *payload, size_t payload_length, Terminal *term)
 {
-  char *payload = argv[0];
-  size_t payload_length = (size_t)argv[1];
-  Terminal *term = argv[2];
-
   buf_T *buf = handle_get_buffer(term->buf_handle);
   String termrequest = { .data = payload, .size = payload_length };
   Object data = STRING_OBJ(termrequest);
@@ -201,7 +197,7 @@ static int on_osc(int command, VTermStringFragment frag, void *user)
   StringBuilder request = KV_INITIAL_VALUE;
   kv_printf(request, "\x1b]%d;", command);
   kv_concat_len(request, frag.str, frag.len);
-  multiqueue_put(main_loop.events, emit_term_request, request.items, (void *)request.size, user);
+  emit_term_request(request.items, request.size, user);
   return 1;
 }
 
@@ -214,7 +210,7 @@ static int on_dcs(const char *command, size_t commandlen, VTermStringFragment fr
   StringBuilder request = KV_INITIAL_VALUE;
   kv_printf(request, "\x1bP%*s", (int)commandlen, command);
   kv_concat_len(request, frag.str, frag.len);
-  multiqueue_put(main_loop.events, emit_term_request, request.items, (void *)request.size, user);
+  emit_term_request(request.items, request.size, user);
   return 1;
 }
 

But since libvterm callbacks are invoked from libuv events, making TermRequest synchronous may be dangerous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior events events, autocommands terminal built-in :terminal or :shell
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants