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

Extraneous line for multiline output in Sage command line #22158

Closed
kwankyu opened this issue Jan 9, 2017 · 16 comments
Closed

Extraneous line for multiline output in Sage command line #22158

kwankyu opened this issue Jan 9, 2017 · 16 comments

Comments

@kwankyu
Copy link
Collaborator

kwankyu commented Jan 9, 2017

To reproduce it, run Sage in the terminal and evaluate the following code. Extra blank lines are printed before outputs as below:

class Foo(object):

    def __repr__(self):
        return "foo"


class Bar(object):

    def __repr__(self):
        return "bar\nbar"


sage: identity_matrix(QQ, 2)

[1 0]
[0 1]
sage: Foo()
foo
sage: Bar()

bar
bar

This was first discussed in https://groups.google.com/forum/#!topic/sage-devel/AYYaUb_9kjw

Upstream: Fixed upstream, but not in a stable release.

CC: @sagetrac-stakemori @tscrim

Component: user interface

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/22158

@kwankyu kwankyu added this to the sage-7.5 milestone Jan 9, 2017
@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 9, 2017

comment:1

The related upstream discussion is in ipython/ipython#10138

@sagetrac-stakemori
Copy link
Mannequin

sagetrac-stakemori mannequin commented Jan 9, 2017

comment:3

Thank you. I will try to make a patch this weekend.

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 9, 2017

comment:4

Replying to @sagetrac-stakemori:

Thank you. I will try to make a patch this weekend.

Did you see the comment posted in the upstream discussion? We may think that the bug is in IPython than in Sage. So we need a patch for IPython. You may submit a pull request of the patch to IPython Github repo.

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 9, 2017

comment:5

Fixed upstream in ipython/ipython#10146

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 9, 2017

Changed upstream from Reported upstream. No feedback yet. to Fixed upstream, but not in a stable release.

@sagetrac-stakemori
Copy link
Mannequin

sagetrac-stakemori mannequin commented Jan 10, 2017

comment:6

Replying to @kwankyu:

I saw the pull request. This has been fixed in IPython. But I think this can be fixed immediately in Sage (how long will it take before the fix will be merged into Sage?). Right now I have a fever, so I avoid coding.

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 10, 2017

comment:7

It will take some time for the fix in the upstream eventually to get into a release of Sage. For the impatient, copy and paste the following to replace the code for write_output_prompt method in sage/local/lib/python/site-packages/IPython/terminal.

    def write_output_prompt(self):
        sys.stdout.write(self.shell.separate_out)
        # If we're not displaying a prompt, it effectively ends with a newline,
        # because the output will be left-aligned.
        self.prompt_end_newline = True

        if self.do_full_cache:
            tokens = self.shell.prompts.out_prompt_tokens()
            prompt_txt = ''.join(s for t, s in tokens)
            if prompt_txt and not prompt_txt.endswith('\n'):
                # Ask for a newline before multiline output
                self.prompt_end_newline = False

            if self.shell.pt_cli:
                self.shell.pt_cli.print_tokens(tokens)
            else:
                sys.stdout.write(prompt_txt) 

@sagetrac-stakemori
Copy link
Mannequin

sagetrac-stakemori mannequin commented Jan 10, 2017

comment:8

For the impatient, copy and paste the following to replace the code for write_output_prompt method in sage/local/lib/python/site-packages/IPython/terminal.

The method write_output_prompt of the class RichPromptDisplayHook in $SAGE_ROOT/local/lib/python/site-packages/IPython/terminal/prompts.py more precisely.

@tscrim
Copy link
Collaborator

tscrim commented Jan 11, 2017

comment:9

We can just patch Sage's IPython in the meantime. This is the fastest fix, as we have to wait for the next version of IPython with the PR included.

I doubt Volker will let this ticket get into the 7.5 release though. :/

@jdemeyer
Copy link

comment:10

Replying to @tscrim:

as we have to wait for the next version of IPython with the PR included.

That would be a pity for such an important major bug like this one ;-)

@sagetrac-stakemori
Copy link
Mannequin

sagetrac-stakemori mannequin commented Jan 14, 2017

comment:11

I made a patch for this problem. I think the attribute prompt_end_newline should be always true.
https://gist.github.com/stakemori/68f42ba2f9ac6f6d581e9525c1c41e07

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 14, 2017

comment:12

Your patch will be redundant once the next release of IPython is incorporated to Sage. Note that the upstream patch was back ported to the current release, which means, I guess, that the fixed IPython would be available in Sage sooner than usual.

Your patch can be used as an (alternative) temporary measure to fix the issue, but should not be merged to Sage.

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jan 31, 2018

comment:13

As Sage's IPython was updated to version 5.5, this issue is now fixed. Nice!

@tscrim
Copy link
Collaborator

tscrim commented Jan 31, 2018

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Jan 31, 2018

comment:14

Indeed!

@tscrim tscrim removed this from the sage-7.5 milestone Jan 31, 2018
@videlec
Copy link
Contributor

videlec commented May 18, 2018

comment:15

closing positively reviewed duplicates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants