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

Make handling of command output more robust #70

Merged
merged 15 commits into from
Nov 9, 2022

Conversation

cdelledonne
Copy link
Owner

No description provided.

@cdelledonne cdelledonne linked an issue Oct 25, 2022 that may be closed by this pull request
@cdelledonne cdelledonne marked this pull request as draft October 25, 2022 16:18
@cdelledonne cdelledonne self-assigned this Oct 25, 2022
@cdelledonne cdelledonne force-pushed the 57-command-output-with-ninja-build-system-broken branch from 9b141fe to f1a1501 Compare October 26, 2022 08:53
@cdelledonne cdelledonne marked this pull request as ready for review October 27, 2022 11:04
@cdelledonne
Copy link
Owner Author

Hey @marwing, I've gotten around to looking into this at last, and I'm fairly happy with the results. Could I ask you to test these changes too? Both Neovim and Vim should now handle output properly, and you should see the Ninja output you'd expect in a normal terminal. I haven't tested on Windows yet, but will do soon.

Feel free to look at the code changes too, but you don't have to. TL;DR I am now printing commands' output (almost) directly into the Vim-CMake console, and only then processing the raw output to strip out ANSI sequences (which is useful for generating the Quickfix list of errors).

@cdelledonne
Copy link
Owner Author

cdelledonne commented Oct 28, 2022

@marwing one more question: I can't seem to have Ninja output colored messages, unless I set -fdiagnostics-color for GCC (or -fcolor-diagnostics for Clang), which yields colored errors and warnings. Is that the expected behavior with Ninja? Otherwise I'm guessing that we need to set some particular terminal property/env variable for Ninja to always output colored messages.

Fun fact, Vim sets the TERM env variable to dumb by default when launching a job, even when requesting the allocation of a PTY. This makes Ninja think it's running in a non-smart terminal (see here) and thus output one message per line, instead of using CR characters to overwrite lines. Setting the TERM variable to a better default (see here) fixed this CR problem, but it did not help with the color problem.

Edit: forgot to say that I also don't see colors when running Ninja just in my terminal, outside of Neovim/Vim.

@marwing
Copy link
Contributor

marwing commented Oct 28, 2022

Could I ask you to test these changes too?

From what I can tell :CMakeBuild works correctly in vim and neovim with the Ninja generator. Although I noticed that vim throws several errors on :CMakeGenerate on master.

I can't seem to have Ninja output colored messages, unless I set -fdiagnostics-color for GCC (or -fcolor-diagnostics for Clang), which yields colored errors and warnings. Is that the expected behavior with Ninja?

This is unfortunately expected with ninja (ninja-build/ninja#174). Since I use ccache with cmake I already have CMake set up with a global env variable (since cmake 2.24, flag before) to enable colors with clang and gcc (https://gitlab.com/marwing/dotfiles/-/blob/5a6ee75daf1e5244d81eb19c5545a239cb8cde20/.config/zsh/.zprofile#L49) so I didn't even notice this. I would guess that people who use ninja already know about and deal with this.

Fun fact, Vim sets the TERM env variable to dumb by default when launching a job, even when requesting the allocation of a PTY.

That seems sort of stupid. Have you found any reason for this?

Setting the TERM variable to a better default (see here) fixed this CR problem, but it did not help with the color problem.

Do you think it is a good idea to default to xterm-256color? The user may not be in a terminal that supports 256 colors.

@cdelledonne
Copy link
Owner Author

Although I noticed that vim throws several errors on :CMakeGenerate on master.

Ah, what errors? What version of Vim did you test with? I don't see anything on my end.

That seems sort of stupid. Have you found any reason for this?

Not really, I tried to find out why but couldn't get anywhere.

Do you think it is a good idea to default to xterm-256color? The user may not be in a terminal that supports 256 colors.

Probably not, I changed it to getenv('TERM'), should be safe I think.

One issue I still do see is that I can't seem to be able to set the PTY's width in Vim, which Ninja relies on to output properly truncated lines. This results in the output to be messed up if the width of the Vim-CMake console is smaller than some of the lines output by Ninja (you can try to run Vim-CMake in a narrow terminal, you should see this issue too). I've opened an issue upstream: vim/vim#11476, let's see if I get any response.

@marwing
Copy link
Contributor

marwing commented Oct 31, 2022

Ah, what errors? What version of Vim did you test with? I don't see anything on my end.

These:

Error detected while processing /home/marwin/Workspace/vim/vim-cmake/autoload/cmake.vim[14]..function cmake#util#PrintNews[1]..<SNR>38_UpdateVersionNumber:
line   15:
E896: Argument of get() must be a List, Dictionary or Blob
Error detected while processing /home/marwin/Workspace/vim/vim-cmake/autoload/cmake.vim[24]..function 29[6]..18:
line    3:
E896: Argument of get() must be a List, Dictionary or Blob
Error detected while processing /home/marwin/Workspace/vim/vim-cmake/autoload/cmake.vim[24]..function 29:
line    6:
E896: Argument of get() must be a List, Dictionary or Blob
Error detected while processing /home/marwin/Workspace/vim/vim-cmake/autoload/cmake.vim[24]..function 29[6]..<SNR>30_SetCurrentConfig[11]..20[4]..18:
line    3:
E896: Argument of get() must be a List, Dictionary or Blob
Press ENTER or type command to continue

with version:

$ vim --version

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Oct 22 2022 19:58:44)
Included patches: 1-813
Compiled by Arch Linux
Huge version without GUI.

and only vim-cmake master in packpath.
Also I must correct myself, these appear when first running any command from vim-cmake. I just happened to always call generate first.
This should be a separate issue if an actual problem and not only a stupid mistake on my part.

One issue I still do see is that I can't seem to be able to set the PTY's width in Vim, which Ninja relies on to output properly truncated lines.

That's interesting. I'm curious of the outcome of this. I would however not block this pr because of that as I doubt too many people run that narrow of a vim instance and the output is not too bad (this patch actually seems to improve it for me). I would put this in a follow up instead and push this as quickly as reasonable to make ninja usable in neovim.

@cdelledonne
Copy link
Owner Author

Regarding your issues in Vim, yes I'd open a new issue, as I don't have a quick answer. Please also try to reproduce with a minimal vimrc when posting the issue.

For the rest, yes I think I'll just merge this PR (I'll actually wait to merge #64 first), and open a follow-up issue for terminal width in Vim.

@cdelledonne
Copy link
Owner Author

I'm merging this one (@marwing FYI). A few gotchas:

@cdelledonne cdelledonne merged commit 0b36508 into master Nov 9, 2022
@cdelledonne cdelledonne deleted the 57-command-output-with-ninja-build-system-broken branch November 9, 2022 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command output with ninja build system broken
2 participants