Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #27275: Fix readline.pyx for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Klein committed Feb 22, 2019
1 parent db4e4a6 commit f21acf8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/sage/libs/readline.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ into it so we can make it redraw the input area.
EXAMPLES::
sage: from sage.libs.readline import *
sage: from sage.cpython.string import bytes_to_str
sage: replace_line('foobar', 0)
sage: set_point(3)
sage: print('current line: ' + repr(copy_text(0, get_end())))
sage: print('current line: ' + repr(bytes_to_str(copy_text(0, get_end()))))
current line: 'foobar'
sage: print('cursor position: {}'.format(get_point()))
cursor position: 3
Expand All @@ -20,7 +21,8 @@ line is removed::
sage: with interleaved_output():
....: print('output')
....: print('current line: ' + repr(copy_text(0, get_end())))
....: print('current line: ' +
....: repr(bytes_to_str(copy_text(0, get_end()))))
....: print('cursor position: {}'.format(get_point()))
output
current line: ''
Expand All @@ -29,7 +31,7 @@ line is removed::
After the interleaved output, the line and cursor is restored to the
old value::
sage: print('current line: ' + repr(copy_text(0, get_end())))
sage: print('current line: ' + repr(bytes_to_str(copy_text(0, get_end()))))
current line: 'foobar'
sage: print('cursor position: {}'.format(get_point()))
cursor position: 3
Expand All @@ -49,6 +51,7 @@ Finally, clear the current line for the remaining doctests::
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function
from sage.cpython.string cimport str_to_bytes


cdef extern from 'readline/readline.h':
Expand Down Expand Up @@ -202,8 +205,9 @@ def copy_text(pos_start, pos_end):
EXAMPLES::
sage: from sage.libs.readline import copy_text, replace_line
sage: from sage.cpython.string import bytes_to_str
sage: replace_line('foobar', 0)
sage: copy_text(1, 5)
sage: bytes_to_str(copy_text(1, 5))
'ooba'
"""
return rl_copy_text(pos_start, pos_end)
Expand All @@ -224,11 +228,12 @@ def replace_line(text, clear_undo):
EXAMPLES::
sage: from sage.libs.readline import copy_text, replace_line
sage: from sage.cpython.string import bytes_to_str
sage: replace_line('foobar', 0)
sage: copy_text(1, 5)
sage: bytes_to_str(copy_text(1, 5))
'ooba'
"""
rl_replace_line(text, clear_undo)
rl_replace_line(str_to_bytes(text), clear_undo)

def initialize():
"""
Expand Down

0 comments on commit f21acf8

Please sign in to comment.