Skip to content

Commit 6825f5b

Browse files
authored
2.3.0
1 parent d368e21 commit 6825f5b

File tree

8 files changed

+101
-61
lines changed

8 files changed

+101
-61
lines changed

README.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,11 @@ to provide the basic curses functionality
1313

1414
## What's New?
1515

16-
### Version 2.2: Progressbar
16+
### Version 2.3: New Input
1717

18-
-Add ProgressBarTypes enum-class
18+
-Rewrite cursesinput function
1919

20-
-Add ProgressBarLocation enum-class
21-
22-
-You can now have a small progress bar that does not clear the screen
23-
24-
-displaymsg() will no longer clear itself.
25-
26-
**-WARNING! This update may break progress bars.**
27-
28-
### Version 2.1: Files 'n' Folders
29-
30-
-Add openfolderdialog()
31-
32-
-Change colours
33-
34-
-Performance improvements for all methods
20+
-Remains backwards-compatible
3521

3622
### Version 2.0: Incompatible api changes
3723

11.3 KB
Binary file not shown.

dist/cursesplus-2.3.0.tar.gz

10.6 KB
Binary file not shown.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44
[project]
55
name = "cursesplus"
6-
version = "2.2.2"
6+
version = "2.3.0"
77
authors = [{name="Enderbyte Programs",email="[email protected]"},]
88
description = "An extension program to curses that offers option menus, message boxes, file dialogs and more"
99
readme = "README.md"

src/__cptest.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
from time import sleep
66

77
def __test__(stdscr):
8-
displaymsg(stdscr,[filedialog.openfolderdialog(stdscr)])
9-
p = ProgressBar(stdscr,100,bar_location=ProgressBarLocations.CENTER)
10-
for i in range(100):
11-
sleep(0.1)
12-
p.step(str(i))
13-
p.done()
8+
cursesplus.messagebox.showinfo(stdscr,cursesinput(stdscr,"Hello",3).splitlines())
149
if __name__ == "__main__":
1510
#Testing things
1611
curses.wrapper(__test__)

src/cursesplus.egg-info/PKG-INFO

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: cursesplus
3-
Version: 2.2.2
3+
Version: 2.3.0
44
Summary: An extension program to curses that offers option menus, message boxes, file dialogs and more
55
Author-email: Enderbyte Programs <[email protected]>
66
Project-URL: Homepage, https://github.com/Enderbyte-Programs/Curses-Plus
@@ -27,25 +27,11 @@ to provide the basic curses functionality
2727

2828
## What's New?
2929

30-
### Version 2.2: Progressbar
30+
### Version 2.3: New Input
3131

32-
-Add ProgressBarTypes enum-class
32+
-Rewrite cursesinput function
3333

34-
-Add ProgressBarLocation enum-class
35-
36-
-You can now have a small progress bar that does not clear the screen
37-
38-
-displaymsg() will no longer clear itself.
39-
40-
**-WARNING! This update may break progress bars.**
41-
42-
### Version 2.1: Files 'n' Folders
43-
44-
-Add openfolderdialog()
45-
46-
-Change colours
47-
48-
-Performance improvements for all methods
34+
-Remains backwards-compatible
4935

5036
### Version 2.0: Incompatible api changes
5137

4.55 KB
Binary file not shown.

src/cursesplus/cp.py

Lines changed: 92 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,100 @@ def displaymsgnodelay(stdscr,message: list):
106106
mi += 1
107107
stdscr.addstr(int(y//2+mi),int(x//2-len(msgl)//2),msgl)
108108
stdscr.refresh()
109-
109+
def __retr_nbl_lst(input:list)->list:
110+
return [l for l in input if str(l) != ""]
111+
def __shft_lst(input:list)->list:
112+
xl = [i for i in input if str(i) != ""]
113+
return xl + ["" for _ in range(1000-len(xl))]
110114

111-
def cursesinput(stdscr,prompt: str):
115+
def cursesinput(stdscr,prompt: str,lines=1,maxlen=0) -> str:
112116
"""
113-
Get a single line input of text from curses. To be used instead of Python standard input()
117+
Get input from the user. Set maxlen to 0 for no maximum
114118
"""
115-
x,y = os.get_terminal_size()
116-
stdscr.erase()
117-
stdscr.addstr(0, 0, f"{prompt} (hit Enter to send)")
118-
119-
editwin = curses.newwin(1,x-2, 2,1)
120-
rectangle(stdscr, 1,0, 3, x-1)
121-
stdscr.refresh()
122-
123-
box = Textbox(editwin)
124-
125-
# Let the user edit until Ctrl-G is struck.
126-
box.edit()
127-
128-
# Get resulting contents
129-
message = box.gather()
130-
return message[0:-1]
119+
mx,my = os.get_terminal_size()
120+
extoffscr = lines > my-3
121+
if extoffscr:
122+
lnrectmaxy = my-2
123+
else:
124+
lnrectmaxy = lines+2
125+
text: list[list[str]] = [[] for _ in range(lines)]
126+
ln=0
127+
col=0
128+
xoffset = 0
129+
while True:
130+
filline(stdscr,0,set_colour(WHITE,BLACK))
131+
stdscr.addstr(0,0,str(prompt+" (Press ctrl-D to submit)")[0:mx-2],set_colour(WHITE,BLACK))
132+
rectangle(stdscr,1,0,lnrectmaxy,mx-1)
133+
chi = 1
134+
for chln in text:
135+
chi+= 1
136+
stdscr.addstr(chi,1,"".join(chln)[xoffset:xoffset+mx-3])
137+
if xoffset > 0:
138+
stdscr.addstr(chi,0,"<",set_colour(BLUE,WHITE))
139+
stdscr.addstr(0,mx-10,f"{ln},{col}",set_colour(WHITE,BLACK))
140+
stdscr.move(ln+2,col-xoffset+1)
141+
142+
stdscr.refresh()
143+
ch = stdscr.getch()
144+
chn = curses.keyname(ch)
145+
if ch == 10 or ch == 13 or ch == curses.KEY_ENTER or ch == curses.KEY_DOWN:
146+
if ln == lines - 1:
147+
curses.beep()
148+
else:
149+
ln += 1
150+
col = 0
151+
elif ch == curses.KEY_LEFT:
152+
if col > 0:
153+
col -= 1
154+
if xoffset > 0:
155+
xoffset -= 1
156+
stdscr.clear()
157+
else:
158+
curses.beep()
159+
elif ch == curses.KEY_RIGHT:
160+
if col < len(__retr_nbl_lst(text[ln])):
161+
col += 1
162+
if col-xoffset > mx-2:
163+
xoffset += 1
164+
stdscr.clear()
165+
else:
166+
curses.beep()
167+
elif ch == curses.KEY_BACKSPACE:
168+
if col > 0:
169+
del text[ln][col-1]
170+
col -= 1
171+
if xoffset > 0:
172+
xoffset -= 1
173+
stdscr.clear()#Fix render errors
174+
175+
else:
176+
curses.beep()
177+
elif ch == curses.KEY_UP:
178+
if ln > 0:
179+
ln -= 1
180+
col = 0
181+
else:
182+
if len(chn) > 1:
183+
#Special char
184+
if chn == b"^D":
185+
stdscr.erase()
186+
return "\n".join(["".join(t) for t in text])
187+
elif chn == b"^K":
188+
text = [[] for _ in range(lines)]#Delete
189+
ln = 0
190+
col = 0
191+
stdscr.erase()
192+
else:
193+
curses.beep()
194+
else:
195+
#append
196+
col += 1
197+
text[ln].insert(col-1,chn.decode())
198+
199+
if col > mx-2:
200+
xoffset += 1
201+
stdscr.clear()
202+
131203

132204
def displayops(stdscr,options: list,title="Please choose an option") -> int:
133205
"""Display an options menu provided by options list. ALso displays title. Returns integer value of selected item."""
@@ -172,6 +244,7 @@ def displayops(stdscr,options: list,title="Please choose an option") -> int:
172244
selected += 1
173245
elif _ch == curses.KEY_BACKSPACE or _ch == 98:
174246
return -1
247+
stdscr.erase()
175248

176249
def optionmenu(stdscr,options:list,title="Please choose an option and press enter") -> int:
177250
"""Alias function to displayops()"""

0 commit comments

Comments
 (0)