@@ -35,6 +35,7 @@ from PyQt5.QtGui import (
3535 QPixmap ,
3636 QStandardItem ,
3737 QStandardItemModel ,
38+ QTextCursor ,
3839)
3940from PyQt5 .QtWidgets import (
4041 QAbstractItemView ,
@@ -1746,12 +1747,30 @@ class MacAttack(QMainWindow):
17461747 self .proxy_output .setHtml ("Proxy testing will output here...\n " )
17471748 self .proxy_output .setReadOnly (True )
17481749 self .proxy_output .setFont (monospace_font )
1749- # Set the maximum height to 200px
1750+ # Set the maximum height to 60px
17501751 self .proxy_output .setMaximumHeight (60 )
17511752 # Add the proxy output area to the layout
17521753 proxy_layout .addWidget (self .proxy_output )
17531754 # Connect the textChanged signal to update the proxy count
17541755 self .proxy_textbox .textChanged .connect (self .update_proxy_count )
1756+ # Set a buffer for the proxy testing console
1757+ self .proxy_output .textChanged .connect (self .trim_proxy_output )
1758+
1759+ def trim_proxy_output (self ):
1760+ """Trim the proxy output log to keep only the last 10 lines."""
1761+ max_lines = 4
1762+
1763+ # Get the current text and split it into lines
1764+ current_text = self .proxy_output .toPlainText ()
1765+ lines = current_text .splitlines ()
1766+
1767+ # If the number of lines exceeds the max_lines, trim the content
1768+ if len (lines ) > max_lines :
1769+ # Keep only the last `max_lines` lines
1770+ lines = lines [- max_lines :]
1771+
1772+ # Update the text area with the last `max_lines` lines
1773+ self .proxy_output .setPlainText ("\n " .join (lines ))
17551774
17561775 def update_proxy_count (self ):
17571776 # Get the number of lines in the proxy_textbox
@@ -2038,13 +2057,17 @@ class MacAttack(QMainWindow):
20382057 color: white;
20392058 background-color: #10273d;
20402059 border: 12px solid #2E2E2E;
2041- """
2060+ """
20422061 )
20432062 self .output_text .setPlainText ("Output LOG:\n Results will appear here.\n " )
20442063 self .output_text .setReadOnly (True )
20452064 monospace_font = QFont ("Lucida Console" , 10 )
20462065 self .output_text .setFont (monospace_font )
20472066 layout .addWidget (self .output_text )
2067+
2068+ # Keep the output log to a maximum of output__history_buffer lines
2069+ self .output__history_buffer = 1000
2070+ self .output_text .textChanged .connect (self .trim_output_log )
20482071 # Error Log Area
20492072 self .error_text = QTextEdit ()
20502073 self .error_text .setStyleSheet (
@@ -2055,19 +2078,80 @@ class MacAttack(QMainWindow):
20552078 border-left: 12px solid #2E2E2E;
20562079 border-right: 12px solid #2E2E2E;
20572080 border-bottom: 0px;
2058- """
2081+ """
20592082 )
20602083 self .error_text .setHtml ("" )
20612084 self .error_text .setHtml (
20622085 """
2063- Error LOG:<br>It's normal for errors to appear down here.
2064- """
2086+ Error LOG:<br>It's normal for errors to appear down here.
2087+ """
20652088 )
20662089 self .error_text .setReadOnly (True )
20672090 self .error_text .setFont (monospace_font )
20682091 layout .addWidget (self .error_text )
20692092 layout .addSpacing (15 ) # Adds space
20702093
2094+ # Keep the log to a maximum of error__history_buffer lines
2095+ self .error__history_buffer = 100
2096+ self .error_text .textChanged .connect (self .trim_error_log )
2097+
2098+ self .error_text .setReadOnly (True )
2099+ self .error_text .setFont (monospace_font )
2100+ layout .addWidget (self .error_text )
2101+ layout .addSpacing (15 ) # Adds space
2102+
2103+ def trim_output_log (self ):
2104+ """Trims the output log to keep only the last output__history_buffer lines."""
2105+ document = self .output_text .document ()
2106+ block_count = document .blockCount ()
2107+ if block_count > self .output__history_buffer :
2108+ cursor = QTextCursor (document )
2109+ cursor .movePosition (QTextCursor .Start ) # Go to the beginning
2110+ for _ in range (block_count - self .output__history_buffer ):
2111+ cursor .select (QTextCursor .BlockUnderCursor )
2112+ cursor .removeSelectedText ()
2113+ cursor .deleteChar () # Ensure newline is removed
2114+
2115+ def trim_error_log (self ):
2116+ """Trims the error log to keep only the last visible lines-based buffer, accounting for line wrapping."""
2117+ # Calculate the number of visible lines
2118+ font_metrics = self .error_text .fontMetrics ()
2119+ line_height = font_metrics .lineSpacing () # Height of a single line
2120+ visible_height = self .error_text .height () # Height of the visible area
2121+
2122+ # Count the total number of lines considering wrapped lines
2123+ document = self .error_text .document ()
2124+ total_wrapped_lines = 0
2125+ for block_index in range (document .blockCount ()):
2126+ block = document .findBlockByNumber (block_index )
2127+ block_layout = block .layout ()
2128+ if block_layout is not None :
2129+ block_height = block_layout .boundingRect ().height ()
2130+ wrapped_lines_in_block = block_height // line_height
2131+ total_wrapped_lines += max (1 , wrapped_lines_in_block ) # At least 1 line per block
2132+
2133+ # Calculate the buffer size as the number of visible slots minus one
2134+ visible_lines = visible_height // line_height
2135+ self .error__history_buffer = max (1 , visible_lines ) # Ensure buffer size is positive
2136+
2137+ # Trim the log if the total wrapped lines exceed the buffer size
2138+ if total_wrapped_lines > self .error__history_buffer :
2139+ cursor = QTextCursor (document )
2140+ cursor .movePosition (QTextCursor .Start ) # Go to the beginning
2141+ lines_to_remove = total_wrapped_lines - self .error__history_buffer
2142+
2143+ # Remove blocks until the wrapped line count is within the buffer size
2144+ while lines_to_remove > 0 :
2145+ block = document .firstBlock ()
2146+ block_layout = block .layout ()
2147+ if block_layout is not None :
2148+ block_height = block_layout .boundingRect ().height ()
2149+ wrapped_lines_in_block = block_height // line_height
2150+ lines_to_remove -= max (1 , wrapped_lines_in_block )
2151+ cursor .select (QTextCursor .BlockUnderCursor )
2152+ cursor .removeSelectedText ()
2153+ cursor .deleteChar () # Ensure newline is removed
2154+
20712155 def SaveTheDay (self ):
20722156 """Save user settings, including window geometry, active tab, and other preferences to the configuration file."""
20732157 user_dir = os .path .expanduser ("~" )
0 commit comments