@@ -29,13 +29,29 @@ class Color:
2929
3030 last_sameline_length = 0
3131
32+ # ── Kalidroid MiniTerminal mode ───────────────────────────────────────────
33+ # The Kalidroid Android app streams wifite's stdout into a MiniTerminal: an
34+ # append-only scrollback view, NOT a terminal emulator. Carriage-return
35+ # redraws (the live attack progress lines) and clear-line escapes therefore
36+ # render as overwritten/garbled text. When --kalidroid is set these are
37+ # flattened into discrete, newline-terminated lines (throttled so a
38+ # per-second timer doesn't flood the view) and the clear-line ops become
39+ # no-ops. ANSI colours are kept — the MiniTerminal parses SGR codes.
40+ kalidroid = False
41+ _kalidroid_last_emit = 0.0
42+ _kalidroid_last_line = ''
43+ _KALIDROID_MIN_INTERVAL = 0.4 # seconds between same-line progress emits
44+
3245 @staticmethod
3346 def p (text ):
3447 """
3548 Prints text using colored format on same line.
3649 Example:
3750 Color.p('{R}This text is red. {W} This text is white')
3851 """
52+ if Color .kalidroid :
53+ Color ._p_kalidroid (text )
54+ return
3955 sys .stdout .write (Color .s (text ))
4056 sys .stdout .flush ()
4157 if '\r ' in text :
@@ -44,6 +60,34 @@ def p(text):
4460 else :
4561 Color .last_sameline_length += len (text )
4662
63+ @staticmethod
64+ def _p_kalidroid (text ):
65+ """
66+ Same as [p] but for the Kalidroid MiniTerminal: a carriage-return
67+ same-line update (e.g. the per-second attack progress line) is emitted
68+ as its own newline-terminated line so the append-only scrollback stays
69+ readable. Identical consecutive redraws and bursts faster than
70+ [_KALIDROID_MIN_INTERVAL] are dropped so timers don't flood the view.
71+ Plain text (no '\\ r') — including the newline-terminated Color.pl prints
72+ — passes through unchanged, so final/result lines are never throttled.
73+ """
74+ if '\r ' not in text :
75+ sys .stdout .write (Color .s (text ))
76+ sys .stdout .flush ()
77+ return
78+ content = text [text .rfind ('\r ' ) + 1 :].rstrip ('\n ' )
79+ if content .strip () == '' :
80+ return # bare '\r' / whitespace-only clear carries no information
81+ import time
82+ now = time .time ()
83+ if (content == Color ._kalidroid_last_line
84+ or now - Color ._kalidroid_last_emit < Color ._KALIDROID_MIN_INTERVAL ):
85+ return
86+ Color ._kalidroid_last_emit = now
87+ Color ._kalidroid_last_line = content
88+ sys .stdout .write (Color .s (content ) + '\n ' )
89+ sys .stdout .flush ()
90+
4791 @staticmethod
4892 def pl (text ):
4993 """Prints text using colored format with trailing new line."""
@@ -71,13 +115,21 @@ def s(text):
71115
72116 @staticmethod
73117 def clear_line ():
118+ # MiniTerminal has no cursor to rewind — the '\r<spaces>\r' erase would
119+ # just append blanks. The flattened progress lines stand on their own.
120+ if Color .kalidroid :
121+ Color .last_sameline_length = 0
122+ return
74123 spaces = ' ' * Color .last_sameline_length
75124 sys .stdout .write ('\r %s\r ' % spaces )
76125 sys .stdout .flush ()
77126 Color .last_sameline_length = 0
78127
79128 @staticmethod
80129 def clear_entire_line ():
130+ if Color .kalidroid :
131+ Color .last_sameline_length = 0
132+ return
81133 import shutil
82134 columns = shutil .get_terminal_size (fallback = (80 , 24 )).columns
83135 Color .p ('\r ' + (' ' * columns ) + '\r ' )
0 commit comments