curses-utils2 0.4.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: curses-utils2
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: A curses utils
5
5
  Project-URL: homepage, https://github.com/shamilbi/curses-utils2
6
6
  Author-email: Shamil Bikineyev <shamilbi@gmail.com>
@@ -0,0 +1 @@
1
+ __version__ = '0.5.0'
@@ -39,8 +39,16 @@ class List3v2(WinProto):
39
39
 
40
40
  def set_win(self, win: curses.window | None):
41
41
  self.win = win
42
- if win:
43
- win.keypad(True)
42
+
43
+ if not win:
44
+ return
45
+
46
+ rows, _ = win.getmaxyx()
47
+ if rows < self.height:
48
+ self.win = None
49
+ return
50
+
51
+ win.keypad(True)
44
52
 
45
53
  def addstr(self, i: int, g: Generator[str], attr: int = 0):
46
54
  if not self.win:
@@ -123,8 +131,8 @@ class List3v2(WinProto):
123
131
  self.cur += 1
124
132
  else:
125
133
  self.win.move(0, 0)
126
- self.win.deleteln()
127
- self.win.deleteln()
134
+ for _ in range(self.height):
135
+ self.win.deleteln()
128
136
  self.cur = rows - 1
129
137
  self.addstr(self.cur, next_s, attr=self.current_color)
130
138
  self.idx += 1
@@ -0,0 +1,57 @@
1
+ import curses
2
+
3
+ from .list3_v2 import List3v2, ListProto3
4
+
5
+
6
+ class List3mProto(ListProto3):
7
+ def record_move_up(self, i: int) -> bool: # type: ignore[empty-body]
8
+ pass
9
+
10
+ def record_move_down(self, i: int) -> bool: # type: ignore[empty-body]
11
+ pass
12
+
13
+
14
+ class List3m(List3v2):
15
+ 'List + move_up(), move_down()'
16
+
17
+ def __init__(
18
+ self,
19
+ proto: List3mProto,
20
+ **kwargs,
21
+ ):
22
+ super().__init__(proto, **kwargs)
23
+ self.proto: List3mProto = proto
24
+
25
+ def move_up(self, i: int):
26
+ if not self.proto.record_move_up(i):
27
+ return
28
+ if self.idx > 0:
29
+ self.idx -= 1
30
+ if self.cur > 0:
31
+ self.cur -= 1
32
+ self.refresh()
33
+
34
+ def move_down(self, i: int):
35
+ if not self.win:
36
+ return
37
+ if not self.proto.record_move_down(i):
38
+ return
39
+ len_ = self.proto.records_len()
40
+ rows, _ = self.win.getmaxyx()
41
+ rows //= self.height
42
+ if self.idx + 1 < len_:
43
+ self.idx += 1
44
+ if self.cur + 1 < rows:
45
+ self.cur += 1
46
+ self.refresh()
47
+
48
+ def handle_input(self, ch: int) -> bool:
49
+ if super().handle_input(ch):
50
+ return True
51
+ if ch == curses.KEY_SR: # Shift-Up
52
+ self.move_up(self.idx)
53
+ elif ch == curses.KEY_SF: # Shift-Down
54
+ self.move_down(self.idx)
55
+ else:
56
+ return False
57
+ return True
@@ -16,9 +16,9 @@ class WinBox:
16
16
  'offy: y offset, offx: x offset'
17
17
  self.body = body
18
18
  self.offy, self.offx = offy, offx
19
+ self.win: curses.window | None = None
19
20
 
20
21
  def set_win(self, win: curses.window | None):
21
- # pylint: disable=attribute-defined-outside-init
22
22
  self.win = win
23
23
 
24
24
  if not win:
@@ -1 +0,0 @@
1
- __version__ = '0.4.0'
File without changes
File without changes