Repository: xonsh/xonsh

Issue:
Prompt displayed on the same line as command output
Consider the following code:

```
echo -n foo
```

. This will result in

```
foozyx@zyx-desktop ~ $
```

on the next line in place of just

```
zyx@zyx-desktop ~ $
```

. Zsh in this case outputs per cent sign:

![highlighted per cent after foo](http://img-fotki.yandex.ru/get/9746/9151298.6/0_b9316_bb69ddd8_orig.png)

(note: attaching a screenshot to show that this sign is highlighted). (Of course, in zsh this is controlled by some option. I do not see why this should be optional though, but in zsh you can customize not only sign presence, but also how it is highlighted and what text should be there exactly (including running some command and displaying its output).)

Xonsh version 0.2.2.



Discussion:
Thanks for reporting this @ZyX-I.  I think that xonsh's current behaviour is the expected behaviour here.  The `-n` option to `echo` is exactly what this enables.  That said, I wouldn't mind it if there was an environment variable that dictated what to append if the command does not have a trailing newline.  For example, `$APPEND_IF_NO_NEWLINE`.  The default for this should be an empty string.

Pull requests welcome!

It's not just zsh that forces the prompt to be printed on a new line. fish does this as well:

![screenshot from 2015-11-04 12-57-03](https://cloud.githubusercontent.com/assets/128854/10927402/96c46a96-82f3-11e5-93f2-09ba1be12c69.png)

(note that the `⏎` is a grey that is not my terminal's default colour)

I think this would be easy to do for anyone who feels up for it.

I would like to work on this, I am guessing I should define the environment variables in `environ.py` but where would I define how it would behave?

a good place would be in base_shell.py maybe in the `default` method

Yeah, I agree with @laerus.  Somewhere in BaseShell. Probably either in default() or postcmd()

Thanks for being willing to take this on @SanketDG!

Any progress on this @SanketDG?
I am trying to close out as many open issues as possible and any help would be greatly appreciated!
No I haven't been able to work on this, sorry. I will try getting on this as soon as I can.

If this is high prio, then anyone else can feel free to work on this.
Thanks! Clearing this out would be nice.

Resolving patch:
diff --git a/xonsh/base_shell.py b/xonsh/base_shell.py
--- a/xonsh/base_shell.py
+++ b/xonsh/base_shell.py
@@ -339,8 +339,12 @@ def default(self, line):
                 hist.last_cmd_rtn = 1  # return code for failure
         finally:
             ts1 = ts1 or time.time()
-            self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee.getvalue())
+            tee_out = tee.getvalue()
+            self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee_out)
             self.accumulated_inputs += src
+            append_newline = env.get('XONSH_APPEND_NEWLINE')
+            if append_newline and not tee_out.endswith(os.linesep):
+                print(os.linesep, end='')
             tee.close()
             self._fix_cwd()
         if builtins.__xonsh_exit__:  # pylint: disable=no-member
diff --git a/xonsh/environ.py b/xonsh/environ.py
--- a/xonsh/environ.py
+++ b/xonsh/environ.py
@@ -179,6 +179,7 @@ def DEFAULT_ENSURERS():
     'VIRTUAL_ENV': (is_string, ensure_string, ensure_string),
     'WIN_UNICODE_CONSOLE': (always_false, setup_win_unicode_console, bool_to_str),
     'XONSHRC': (is_env_path, str_to_env_path, env_path_to_str),
+    'XONSH_APPEND_NEWLINE': (is_bool, to_bool, bool_to_str),
     'XONSH_AUTOPAIR': (is_bool, to_bool, bool_to_str),
     'XONSH_CACHE_SCRIPTS': (is_bool, to_bool, bool_to_str),
     'XONSH_CACHE_EVERYTHING': (is_bool, to_bool, bool_to_str),
@@ -325,6 +326,7 @@ def DEFAULT_VALUES():
                                                          'share')),
         'XONSHCONFIG': xonshconfig,
         'XONSHRC': default_xonshrc,
+        'XONSH_APPEND_NEWLINE': False,
         'XONSH_AUTOPAIR': False,
         'XONSH_CACHE_SCRIPTS': True,
         'XONSH_CACHE_EVERYTHING': False,
@@ -645,6 +647,9 @@ def DEFAULT_DOCS():
             "On Linux & Mac OSX: ``['/etc/xonshrc', '~/.xonshrc']``\n"
             "\nOn Windows: "
             "``['%ALLUSERSPROFILE%\\\\xonsh\\\\xonshrc', '~/.xonshrc']``")),
+    'XONSH_APPEND_NEWLINE': VarDocs(
+        'Append new line when a partial line is preserved in output.'
+    ),
     'XONSH_AUTOPAIR': VarDocs(
         'Whether Xonsh will auto-insert matching parentheses, brackets, and '
         'quotes. Only available under the prompt-toolkit shell.'


Test patch: