-
Notifications
You must be signed in to change notification settings - Fork 25
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
nanorc not found in elevated shell #34
Comments
This is most likely WONTFIX. On Linux, colors are implemented by sending special control characters to the terminal, so they work as long as the terminal (emulator) recognizes them, and it does not matter whether they are sent via pipes or an SSH connection. On Windows, colors are implemented by calling Windows APIs directly, so it will not work over SSH. I believe MSYS2 nano does not have such limitation, but it has others. For example, Alt-Delete (to delete the entire line) works only in MinTTY and does not work in CMD. |
The new Windows terminal supports both console colors and ANSI colors, so using normal ANSI colors, the control codes you speak of, will work correctly for anyone using a recent version of Windows. It will also work in the older console app in Windows 10 at least. As for Windows console colors, they generally do work over ssh. For example, Chocolatey uses them and it works fine in an ssh session. This is an example of a PowerShell command that uses console colors: write-host TEST -foregroundcolor magenta . And this is an example of ANSI colored output: write "`e[95mTEST`e[0m" . In the older Windows PowerShell use this instead: write ([char]27 + "[95mTEST" + [char]27 + "[0m") . Regardless, using console colors should be fine, but the fact that they don't work over ssh indicates some other problem. I can take a look at this, I'd like it to work. |
I forgot to mention that vim also works fine over ssh to Windows. |
In your example you sent ANSI escape codes directly, and they turned out to work, which was expected behavior. But GNU nano (not necessarily nano-win) doesn't send ANSI codes itself; it uses the ncurses library to control the terminal, which has a dedicated win32 console driver to manipulate the terminal with Windows APIs. I suspect it is possible to disable the win32 console driver (see 'build_nano-win.sh' for how ncurses is configured), but this will also make nano-win unusable on Windows 7, or on legacy console on Windows 10. So hardly is it an option. |
I think I have enough info now to see if there's a simple solution and I will take a look, thank you. |
@rkitover I'm trying to get this to work on Pwsh (core) under native Win10 (not via WSL), but no success. It runs correctly, but no colors at all! Can you post your working
I don't quite understand, what is the problem? |
@eabase these builds work fine in PSCore in conhost and in the new terminal, here we were discussing a different issue, and this has nothing to do with WSL. Run this script: https://gist.github.com/rkitover/b0831d048755c7d034b0a936b2a50604 , and make sure to add |
@rkitover, I am using the built-in OpenSSH server of Windows ( |
Oh really? I didn't expect it to work. |
@akuropka I realized that the choco package for openssh is extremely out of date and I installed 8.6p1 and updated to latest nano build but I still don't see colors over ssh, I haven't had a chance to look into this more yet. |
I think I found the issue. I have this in my include "/users/rkitover/.nano/*.nanorc" in the terminal this loads the syntax files which I got from here: https://github.com/scopatz/nanorc This works fine in the normal terminal, but does not work in an ssh session for some reason. However, if I use a command such as: nano --rcfile .nanorc .bashrc then the colors work fine! I can't figure out yet what is different in the environment of the ssh session to cause that. |
It seems that diff --git a/src/utils.c b/src/utils.c
index 555b8421..fef5a96d 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -38,7 +38,7 @@ void get_homedir(void)
/* When HOME isn't set, or when we're root, get the home directory
* from the password file instead. */
- if (homenv == NULL || IsUserAnAdmin())
+ if (homenv == NULL && IsUserAnAdmin())
homenv = getenv("ALLUSERSPROFILE");
/* Only set homedir if some home directory could be determined, |
@rkitover, nice to see your progress. |
@akuropka as far as I know ssh sessions are elevated automatically on Windows and I remove the My problem is that the I think my patch is reasonable, if |
and
are not the same because your code does not cover the case |
Maybe, I should probably do a proper PR for this and think this through fully. |
There are also a couple of build issues I had to deal with, so might as well do that. |
Only use ALLUSERPROFILE for home dir when USERPROFILE is not set, even for admin users. Fix lhmouse#34. Also on Windows when looking for the rc, look in getenv("APPDATA") instead of getenv("XDG_CONFIG_HOME"), which is mostly equivalent. Signed-off-by: Rafael Kitover <[email protected]>
Only use ALLUSERPROFILE for home dir when USERPROFILE is not set, even for admin users. Fix lhmouse#34. Also on Windows when looking for the rc, look in getenv("APPDATA") instead of getenv("XDG_CONFIG_HOME"), which is mostly equivalent. Signed-off-by: Rafael Kitover <[email protected]>
OS: Microsoft Windows [Version 10.0.22523.1000]
nano: GNU nano from git, v5.9-10-gbe0fb5d4a
ssh: OpenSSH_for_Windows_8.6p1, LibreSSL 3.3.3
When using nano in the Windows terminal in PowerShell, syntax highlighting
colors work correctly.
But in an ssh session to Windows, there are no colors.
I downloaded nano from your builds page:
https://files.lhmouse.com/nano-win/
I am using OpenSSH for Windows with the shell set to the latest PowerShell:
BTW, the package in Chocolatey is ancient, and I wrote this installer script:
https://gist.github.com/rkitover/b0831d048755c7d034b0a936b2a50604
The text was updated successfully, but these errors were encountered: