9
9
10
10
# Reusable private utility class
11
11
class myInput :
12
- def __init__ (self ,
13
- word_color : str = colors .foreground ["default" ],
14
- password : bool = False ,
12
+ def __init__ (self ,
13
+ word_color : str = colors .foreground ["default" ],
14
+ password : bool = False ,
15
15
hidden : str = '*'
16
16
):
17
- ''' Constructor for myInput
17
+ ''' Constructor for myInput
18
18
Args:
19
19
word_color: color of input characters.
20
20
password: Whether input is password.
@@ -109,10 +109,10 @@ def input(self):
109
109
@keyhandler .init
110
110
class Bullet :
111
111
def __init__ (
112
- self ,
112
+ self ,
113
113
prompt : str = "" ,
114
- choices : list = [],
115
- bullet : str = "●" ,
114
+ choices : list = [],
115
+ bullet : str = "●" ,
116
116
bullet_color : str = colors .foreground ["default" ],
117
117
word_color : str = colors .foreground ["default" ],
118
118
word_on_switch : str = colors .REVERSE ,
@@ -151,12 +151,12 @@ def __init__(
151
151
self .pad_right = pad_right
152
152
153
153
self .max_width = len (max (self .choices , key = len )) + self .pad_right
154
-
154
+
155
155
def renderBullets (self ):
156
156
for i in range (len (self .choices )):
157
157
self .printBullet (i )
158
158
utils .forceWrite ('\n ' )
159
-
159
+
160
160
def printBullet (self , idx ):
161
161
utils .forceWrite (' ' * (self .indent + self .align ))
162
162
back_color = self .background_on_switch if idx == self .pos else self .background_color
@@ -170,6 +170,7 @@ def printBullet(self, idx):
170
170
utils .moveCursorHead ()
171
171
172
172
@keyhandler .register (ARROW_UP_KEY )
173
+ @keyhandler .register (VIM_UP_KEY )
173
174
def moveUp (self ):
174
175
if self .pos - 1 < 0 :
175
176
return
@@ -182,6 +183,7 @@ def moveUp(self):
182
183
self .printBullet (self .pos )
183
184
184
185
@keyhandler .register (ARROW_DOWN_KEY )
186
+ @keyhandler .register (VIM_DOWN_KEY )
185
187
def moveDown (self ):
186
188
if self .pos + 1 >= len (self .choices ):
187
189
return
@@ -227,10 +229,10 @@ def launch(self, default = None):
227
229
@keyhandler .init
228
230
class Check :
229
231
def __init__ (
230
- self ,
232
+ self ,
231
233
prompt : str = "" ,
232
- choices : list = [],
233
- check : str = "√" ,
234
+ choices : list = [],
235
+ check : str = "√" ,
234
236
check_color : str = colors .foreground ["default" ],
235
237
check_on_switch : str = colors .REVERSE ,
236
238
word_color : str = colors .foreground ["default" ],
@@ -272,12 +274,12 @@ def __init__(
272
274
self .pad_right = pad_right
273
275
274
276
self .max_width = len (max (self .choices , key = len )) + self .pad_right
275
-
277
+
276
278
def renderRows (self ):
277
279
for i in range (len (self .choices )):
278
280
self .printRow (i )
279
281
utils .forceWrite ('\n ' )
280
-
282
+
281
283
def printRow (self , idx ):
282
284
utils .forceWrite (' ' * (self .indent + self .align ))
283
285
back_color = self .background_on_switch if idx == self .pos else self .background_color
@@ -297,6 +299,7 @@ def toggleRow(self):
297
299
self .printRow (self .pos )
298
300
299
301
@keyhandler .register (ARROW_UP_KEY )
302
+ @keyhandler .register (VIM_UP_KEY )
300
303
def moveUp (self ):
301
304
if self .pos - 1 < 0 :
302
305
return
@@ -309,6 +312,7 @@ def moveUp(self):
309
312
self .printRow (self .pos )
310
313
311
314
@keyhandler .register (ARROW_DOWN_KEY )
315
+ @keyhandler .register (VIM_DOWN_KEY )
312
316
def moveDown (self ):
313
317
if self .pos + 1 >= len (self .choices ):
314
318
return
@@ -357,8 +361,8 @@ def launch(self, default = []):
357
361
358
362
class YesNo :
359
363
def __init__ (
360
- self ,
361
- prompt ,
364
+ self ,
365
+ prompt ,
362
366
indent = 0 ,
363
367
word_color = colors .foreground ["default" ]
364
368
):
@@ -376,7 +380,7 @@ def valid(self, ans):
376
380
utils .forceWrite ('\b ' * len (ans ))
377
381
return False
378
382
return True
379
-
383
+
380
384
def launch (self , default = 'y' ):
381
385
default = default .lower ()
382
386
if not (default == 'y' or default == 'n' ):
@@ -394,9 +398,9 @@ def launch(self, default = 'y'):
394
398
395
399
class Input :
396
400
def __init__ (
397
- self ,
398
- prompt ,
399
- indent = 0 ,
401
+ self ,
402
+ prompt ,
403
+ indent = 0 ,
400
404
word_color = colors .foreground ["default" ],
401
405
strip = False ,
402
406
pattern = ""
@@ -408,7 +412,7 @@ def __init__(
408
412
self .word_color = word_color
409
413
self .strip = strip
410
414
self .pattern = pattern
411
-
415
+
412
416
def valid (self , ans ):
413
417
if not bool (re .match (self .pattern , ans )):
414
418
utils .moveCursorUp (1 )
@@ -443,10 +447,10 @@ def launch(self, default = ""):
443
447
444
448
class Password :
445
449
def __init__ (
446
- self ,
447
- prompt ,
448
- indent = 0 ,
449
- hidden = '*' ,
450
+ self ,
451
+ prompt ,
452
+ indent = 0 ,
453
+ hidden = '*' ,
450
454
word_color = colors .foreground ["default" ]
451
455
):
452
456
self .indent = indent
@@ -455,16 +459,16 @@ def __init__(
455
459
self .prompt = prompt
456
460
self .hidden = hidden
457
461
self .word_color = word_color
458
-
462
+
459
463
def launch (self ):
460
464
utils .forceWrite (' ' * self .indent + self .prompt )
461
465
return myInput (password = True , hidden = self .hidden , word_color = self .word_color ).input ()
462
466
463
467
class Numbers :
464
468
def __init__ (
465
- self ,
466
- prompt ,
467
- indent = 0 ,
469
+ self ,
470
+ prompt ,
471
+ indent = 0 ,
468
472
word_color = colors .foreground ["default" ],
469
473
type = float
470
474
):
@@ -474,7 +478,7 @@ def __init__(
474
478
self .prompt = prompt
475
479
self .word_color = word_color
476
480
self .type = type
477
-
481
+
478
482
def valid (self , ans ):
479
483
try :
480
484
float (ans )
@@ -485,7 +489,7 @@ def valid(self, ans):
485
489
utils .forceWrite (' ' * len (ans ))
486
490
utils .forceWrite ('\b ' * len (ans ))
487
491
return False
488
-
492
+
489
493
def launch (self , default = None ):
490
494
if default is not None :
491
495
try :
@@ -505,9 +509,9 @@ def launch(self, default = None):
505
509
506
510
class VerticalPrompt :
507
511
def __init__ (
508
- self ,
509
- components ,
510
- spacing = 1 ,
512
+ self ,
513
+ components ,
514
+ spacing = 1 ,
511
515
separator = "" ,
512
516
separator_color = colors .foreground ["default" ]
513
517
):
@@ -524,7 +528,7 @@ def __init__(
524
528
def summarize (self ):
525
529
for prompt , answer in self .result :
526
530
print (prompt , answer )
527
-
531
+
528
532
def launch (self ):
529
533
for ui in self .components :
530
534
self .result .append ((ui .prompt , ui .launch ()))
@@ -537,9 +541,9 @@ def launch(self):
537
541
@keyhandler .init
538
542
class ScrollBar :
539
543
def __init__ (
540
- self ,
544
+ self ,
541
545
prompt : str = "" ,
542
- choices : list = [],
546
+ choices : list = [],
543
547
pointer = "→" ,
544
548
up_indicator : str = "↑" ,
545
549
down_indicator : str = "↓" ,
@@ -592,7 +596,7 @@ def __init__(
592
596
# scrollbar won't move if pos is in range [top, top + height)
593
597
# scrollbar moves up if pos < top
594
598
# scrollbar moves down if pos > top + height - 1
595
-
599
+
596
600
def renderRows (self ):
597
601
self .printRow (self .top , indicator = self .up_indicator if self .top != 0 else '' )
598
602
utils .forceWrite ('\n ' )
@@ -604,7 +608,7 @@ def renderRows(self):
604
608
605
609
self .printRow (i + 1 , indicator = self .down_indicator if self .top + self .height != len (self .choices ) else '' )
606
610
utils .forceWrite ('\n ' )
607
-
611
+
608
612
def printRow (self , idx , indicator = '' ):
609
613
utils .forceWrite (' ' * (self .indent + self .align ))
610
614
back_color = self .background_on_switch if idx == self .pos else self .background_color
@@ -620,6 +624,7 @@ def printRow(self, idx, indicator=''):
620
624
utils .moveCursorHead ()
621
625
622
626
@keyhandler .register (ARROW_UP_KEY )
627
+ @keyhandler .register (VIM_UP_KEY )
623
628
def moveUp (self ):
624
629
if self .pos == self .top :
625
630
if self .top == 0 :
@@ -640,6 +645,7 @@ def moveUp(self):
640
645
self .printRow (self .pos )
641
646
642
647
@keyhandler .register (ARROW_DOWN_KEY )
648
+ @keyhandler .register (VIM_DOWN_KEY )
643
649
def moveDown (self ):
644
650
if self .pos == self .top + self .height - 1 :
645
651
if self .top + self .height == len (self .choices ):
@@ -688,7 +694,7 @@ def launch(self):
688
694
689
695
class SlidePrompt :
690
696
def __init__ (
691
- self ,
697
+ self ,
692
698
components
693
699
):
694
700
self .idx = 0
0 commit comments