Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
506bf73d
Commit
506bf73d
authored
Jan 20, 2008
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #1048820 from Stefan Wehr: add insert-mode editing to Textbox.
Fix an off-by-one error I noticed.
parent
46fbc66a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
13 deletions
+35
-13
Doc/whatsnew/2.6.rst
Doc/whatsnew/2.6.rst
+5
-2
Lib/curses/textpad.py
Lib/curses/textpad.py
+25
-11
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Doc/whatsnew/2.6.rst
View file @
506bf73d
...
...
@@ -868,16 +868,19 @@ complete list of changes, or look through the CVS logs for all the details.
.. Revision 57769
* A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes
the display characters for a certain number of characters on a single line.
(Contributed by Fabian Kreutz.)
::
# Boldface text starting at y=0,x=21
# and affecting the rest of the line.
stdscr.chgat(0,21, curses.A_BOLD)
(Contributed by Fabian Kreutz.)
The :class:`Textbox` class in the :mod:`curses.textpad` module
now supports editing in insert mode as well as overwrite mode.
Insert mode is enabled by supplying a true value for the *insert_mode*
parameter when creating the :class:`Textbox` instance.
* The :mod:`decimal` module was updated to version 1.66 of
`the General Decimal Specification <http://www2.hursley.ibm.com/decimal/decarith.html>`__. New features
...
...
Lib/curses/textpad.py
View file @
506bf73d
...
...
@@ -39,8 +39,9 @@ class Textbox:
KEY_LEFT = Ctrl-B, KEY_RIGHT = Ctrl-F, KEY_UP = Ctrl-P, KEY_DOWN = Ctrl-N
KEY_BACKSPACE = Ctrl-h
"""
def
__init__
(
self
,
win
):
def
__init__
(
self
,
win
,
insert_mode
=
False
):
self
.
win
=
win
self
.
insert_mode
=
insert_mode
(
self
.
maxy
,
self
.
maxx
)
=
win
.
getmaxyx
()
self
.
maxy
=
self
.
maxy
-
1
self
.
maxx
=
self
.
maxx
-
1
...
...
@@ -49,9 +50,10 @@ class Textbox:
win
.
keypad
(
1
)
def
_end_of_line
(
self
,
y
):
"Go to the location of the first blank on the given line."
"""Go to the location of the first blank on the given line,
returning the index of the last non-blank character."""
last
=
self
.
maxx
while
1
:
while
True
:
if
ascii
.
ascii
(
self
.
win
.
inch
(
y
,
last
))
!=
ascii
.
SP
:
last
=
min
(
self
.
maxx
,
last
+
1
)
break
...
...
@@ -60,19 +62,31 @@ class Textbox:
last
=
last
-
1
return
last
def
_insert_printable_char
(
self
,
ch
):
(
y
,
x
)
=
self
.
win
.
getyx
()
if
y
<
self
.
maxy
or
x
<
self
.
maxx
:
if
self
.
insert_mode
:
oldch
=
self
.
win
.
inch
()
# The try-catch ignores the error we trigger from some curses
# versions by trying to write into the lowest-rightmost spot
# in the window.
try
:
self
.
win
.
addch
(
ch
)
except
curses
.
error
:
pass
if
self
.
insert_mode
:
(
backy
,
backx
)
=
self
.
win
.
getyx
()
if
ascii
.
isprint
(
oldch
):
self
.
_insert_printable_char
(
oldch
)
self
.
win
.
move
(
backy
,
backx
)
def
do_command
(
self
,
ch
):
"Process a single editing command."
(
y
,
x
)
=
self
.
win
.
getyx
()
self
.
lastcmd
=
ch
if
ascii
.
isprint
(
ch
):
if
y
<
self
.
maxy
or
x
<
self
.
maxx
:
# The try-catch ignores the error we trigger from some curses
# versions by trying to write into the lowest-rightmost spot
# in the window.
try
:
self
.
win
.
addch
(
ch
)
except
curses
.
error
:
pass
self
.
_insert_printable_char
(
ch
)
elif
ch
==
ascii
.
SOH
:
# ^a
self
.
win
.
move
(
y
,
0
)
elif
ch
in
(
ascii
.
STX
,
curses
.
KEY_LEFT
,
ascii
.
BS
,
curses
.
KEY_BACKSPACE
):
...
...
@@ -139,7 +153,7 @@ class Textbox:
if
stop
==
0
and
self
.
stripspaces
:
continue
for
x
in
range
(
self
.
maxx
+
1
):
if
self
.
stripspaces
and
x
==
stop
:
if
self
.
stripspaces
and
x
>
stop
:
break
result
=
result
+
chr
(
ascii
.
ascii
(
self
.
win
.
inch
(
y
,
x
)))
if
self
.
maxy
>
0
:
...
...
Misc/ACKS
View file @
506bf73d
...
...
@@ -696,6 +696,7 @@ Bob Watson
Aaron Watters
Henrik Weber
Corran Webster
Stefan Wehr
Zack Weinberg
Edward Welbourne
Cliff Wells
...
...
Misc/NEWS
View file @
506bf73d
...
...
@@ -390,6 +390,10 @@ Library
- #1837: The queue module now also supports a LIFO queue and a priority queue.
- Patch #1048820: Add insert-mode editing to curses.textpad.Textbox
(patch by Stefan Wehr). Also, fix an off-by-one bug in
Textbox.gather().
- Issue #1831: ctypes now raises a TypeError if conflicting positional
and named arguments are passed to a Structure or Union initializer.
When too many positional arguments are passed, also a TypeError is
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment