Add 'Active' column to DataTable with visual indicators for entry status
This commit is contained in:
		
							parent
							
								
									e83db8ce67
								
							
						
					
					
						commit
						a399b04c99
					
				
					 1 changed files with 9 additions and 6 deletions
				
			
		| 
						 | 
					@ -162,6 +162,7 @@ class HostsManagerApp(App):
 | 
				
			||||||
        table.show_header = True
 | 
					        table.show_header = True
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        # Create column labels with sort indicators
 | 
					        # Create column labels with sort indicators
 | 
				
			||||||
 | 
					        active_label = "Active"
 | 
				
			||||||
        ip_label = "IP Address"
 | 
					        ip_label = "IP Address"
 | 
				
			||||||
        hostname_label = "Canonical Hostname"
 | 
					        hostname_label = "Canonical Hostname"
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
| 
						 | 
					@ -173,8 +174,8 @@ class HostsManagerApp(App):
 | 
				
			||||||
            arrow = "↑" if self.sort_ascending else "↓"
 | 
					            arrow = "↑" if self.sort_ascending else "↓"
 | 
				
			||||||
            hostname_label = f"{arrow} Canonical Hostname"
 | 
					            hostname_label = f"{arrow} Canonical Hostname"
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        # Add columns with proper labels
 | 
					        # Add columns with proper labels (Active column first)
 | 
				
			||||||
        table.add_columns(ip_label, hostname_label)
 | 
					        table.add_columns(active_label, ip_label, hostname_label)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        # Add rows
 | 
					        # Add rows
 | 
				
			||||||
        for entry in self.hosts_file.entries:
 | 
					        for entry in self.hosts_file.entries:
 | 
				
			||||||
| 
						 | 
					@ -183,15 +184,17 @@ class HostsManagerApp(App):
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            # Add row with styling based on active status
 | 
					            # Add row with styling based on active status
 | 
				
			||||||
            if entry.is_active:
 | 
					            if entry.is_active:
 | 
				
			||||||
                # Active entries in green
 | 
					                # Active entries in green with checkmark
 | 
				
			||||||
 | 
					                active_text = Text("✓", style="bold green")
 | 
				
			||||||
                ip_text = Text(entry.ip_address, style="bold green")
 | 
					                ip_text = Text(entry.ip_address, style="bold green")
 | 
				
			||||||
                hostname_text = Text(canonical_hostname, style="bold green")
 | 
					                hostname_text = Text(canonical_hostname, style="bold green")
 | 
				
			||||||
                table.add_row(ip_text, hostname_text)
 | 
					                table.add_row(active_text, ip_text, hostname_text)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                # Inactive entries in dim yellow with italic (no # prefix in IP column)
 | 
					                # Inactive entries in dim yellow with italic (no checkmark)
 | 
				
			||||||
 | 
					                active_text = Text("", style="dim yellow italic")
 | 
				
			||||||
                ip_text = Text(entry.ip_address, style="dim yellow italic")
 | 
					                ip_text = Text(entry.ip_address, style="dim yellow italic")
 | 
				
			||||||
                hostname_text = Text(canonical_hostname, style="dim yellow italic")
 | 
					                hostname_text = Text(canonical_hostname, style="dim yellow italic")
 | 
				
			||||||
                table.add_row(ip_text, hostname_text)
 | 
					                table.add_row(active_text, ip_text, hostname_text)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def restore_cursor_position(self, previous_entry) -> None:
 | 
					    def restore_cursor_position(self, previous_entry) -> None:
 | 
				
			||||||
        """Restore cursor position after reload, maintaining selection if possible."""
 | 
					        """Restore cursor position after reload, maintaining selection if possible."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue