Repository: xonsh/xonsh

Issue:
Weird Drawing of nano
`nano` draws... weirdly under xonsh 0.6.0, but fine under bash.


Discussion:
Thanks for reporting @astronouth7303! It draws fine for me, but it does seem to eat control sequences for me sometimes like ^X
![screenshot from 2017-11-28 16-21-13](https://user-images.githubusercontent.com/401438/33348327-050130ca-d464-11e7-991d-2462df830468.png)

The header isn't drawn, the footer is drawn badly, and the cursor is in the wrong place.
hmm it is like it is getting the wrong terminal size.  Have you tried it in other terminal emulators?
On further testing, xonsh on bash on QTerminal works fine. xonsh on LilyTerm (VTE) doesn't work. Bash on LilyTerm works. xonsh on QTerminal fails.
Good to know! Probably an issue somewhere with termios...
This might be sizing issues. `man` isn't formatting right, either.
Also, which shell are you using? Readline or PTK?
PTK.
And `stty size` appears to be reporting the correct value....
Sorted it. `$COLUMNS` and `$LINES` were set incorrectly. Deleting them fixed it.

Should we do anything about them in xonsh? The default would be to set a xontrib to do it, but I don't like having default xonsh being potentially broken.
Weird, yeah, default xonsh should not be broken and I think this should be a fix in xonsh itself.  On my machine COLUMNS and LINES aren't set at all...  Also Bash is doing something weird where these aren't real variables (if you look at the output of `env`) but then if you do `echo $LINES` it will give the right value.

Maybe we should be popping these variables out of the environment when we run a subprocess?  Or putting them in at the proper value?
My initial thought was to remove them from the environment on initialization.

Maybe with a bundled xontrib that will add them to the environment and update them when the terminal changes? (Which implies an event that fires when the terminal changes size.)
I am all for that, but it seems like it shouldn't even be a bundled xontrib, but just part of xonsh. Though I wouldn't say no to a bundled xontrib :) 
I'd want to do more research on the role of `$LINES` & `$COLUMNS` and how applications use them before including them in the default environment, especially since this is in opposition to other shells.
Turns out Bash considers COLUMNS and LINES local variables, and so they are not exported: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html
So, unset them during environment initialization?

Resolving patch:
diff --git a/xonsh/environ.py b/xonsh/environ.py
--- a/xonsh/environ.py
+++ b/xonsh/environ.py
@@ -1205,6 +1205,9 @@ def default_env(env=None):
     ctx = dict(BASE_ENV)
     ctx.update(os_environ)
     ctx['PWD'] = _get_cwd() or ''
+    # These can cause problems for programs (#2543)
+    ctx.pop('LINES', None)
+    ctx.pop('COLUMNS', None)
     # other shells' PROMPT definitions generally don't work in XONSH:
     try:
         del ctx['PROMPT']


Test patch:
diff --git a/tests/test_environ.py b/tests/test_environ.py
--- a/tests/test_environ.py
+++ b/tests/test_environ.py
@@ -11,7 +11,7 @@
 import pytest
 
 from xonsh.commands_cache import CommandsCache
-from xonsh.environ import Env, load_static_config, locate_binary, DEFAULT_ENSURERS, DEFAULT_VALUES
+from xonsh.environ import Env, load_static_config, locate_binary, DEFAULT_ENSURERS, DEFAULT_VALUES, default_env
 
 from tools import skip_if_on_unix
 
@@ -233,3 +233,15 @@ def test_int_bool_envvars_have_ensurers():
     key_mask = set(itertools.compress(DEFAULT_VALUES.keys(), bool_ints))
     ensurer_keys = set(DEFAULT_ENSURERS.keys())
     assert len(key_mask.intersection(ensurer_keys)) == len(key_mask)
+
+
+def test_no_lines_columns():
+    os.environ['LINES'] = 'spam'
+    os.environ['COLUMNS'] = 'eggs'
+    try:
+        env = default_env()
+        assert 'LINES' not in env
+        assert 'COLUMNS' not in env
+    finally:
+        del os.environ['LINES']
+        del os.environ['COLUMNS']