MCPcopy Index your code
hub / github.com/python/cpython / Textbox

Class Textbox

Lib/curses/textpad.py:19–191  ·  view source on GitHub ↗

Editing widget using the interior of a window object. Supports the following Emacs-like key bindings: Ctrl-A Go to left edge of window. Ctrl-B Cursor left, wrapping to previous line if appropriate. Ctrl-D Delete character under cursor. Ctrl-E Go to right edg

Source from the content-addressed store, hash-verified

17 win.addch(lry, ulx, curses.ACS_LLCORNER)
18
19class Textbox:
20 """Editing widget using the interior of a window object.
21 Supports the following Emacs-like key bindings:
22
23 Ctrl-A Go to left edge of window.
24 Ctrl-B Cursor left, wrapping to previous line if appropriate.
25 Ctrl-D Delete character under cursor.
26 Ctrl-E Go to right edge (stripspaces off) or end of line (stripspaces on).
27 Ctrl-F Cursor right, wrapping to next line when appropriate.
28 Ctrl-G Terminate, returning the window contents.
29 Ctrl-H Delete character backward.
30 Ctrl-J Terminate if the window is 1 line, otherwise insert newline.
31 Ctrl-K If line is blank, delete it, otherwise clear to end of line.
32 Ctrl-L Refresh screen.
33 Ctrl-N Cursor down; move down one line.
34 Ctrl-O Insert a blank line at cursor location.
35 Ctrl-P Cursor up; move up one line.
36
37 Move operations do nothing if the cursor is at an edge where the movement
38 is not possible. The following synonyms are supported where possible:
39
40 KEY_LEFT = Ctrl-B, KEY_RIGHT = Ctrl-F, KEY_UP = Ctrl-P, KEY_DOWN = Ctrl-N
41 KEY_BACKSPACE = Ctrl-h
42 """
43 def __init__(self, win, insert_mode=False):
44 self.win = win
45 self.insert_mode = insert_mode
46 self._update_max_yx()
47 self.stripspaces = 1
48 self.lastcmd = None
49 win.keypad(1)
50
51 def _update_max_yx(self):
52 maxy, maxx = self.win.getmaxyx()
53 self.maxy = maxy - 1
54 self.maxx = maxx - 1
55
56 def _end_of_line(self, y):
57 """Go to the location of the first blank on the given line,
58 returning the index of the last non-blank character."""
59 self._update_max_yx()
60 last = self.maxx
61 while True:
62 if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
63 last = min(self.maxx, last+1)
64 break
65 elif last == 0:
66 break
67 last = last - 1
68 return last
69
70 def _insert_printable_char(self, ch):
71 self._update_max_yx()
72 (y, x) = self.win.getyx()
73 backyx = None
74 while y < self.maxy or x < self.maxx:
75 if self.insert_mode:
76 oldch = self.win.inch()

Callers 1

test_editboxFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_editboxFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…