Enhance DataTable row styling by using Rich Text for active and inactive entries
This commit is contained in:
		
							parent
							
								
									bcded3105b
								
							
						
					
					
						commit
						9cd2b5c3fe
					
				
					 1 changed files with 11 additions and 3 deletions
				
			
		| 
						 | 
					@ -9,6 +9,7 @@ from textual.containers import Horizontal, Vertical
 | 
				
			||||||
from textual.widgets import Header, Footer, Static, DataTable
 | 
					from textual.widgets import Header, Footer, Static, DataTable
 | 
				
			||||||
from textual.binding import Binding
 | 
					from textual.binding import Binding
 | 
				
			||||||
from textual.reactive import reactive
 | 
					from textual.reactive import reactive
 | 
				
			||||||
 | 
					from rich.text import Text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .core.parser import HostsParser
 | 
					from .core.parser import HostsParser
 | 
				
			||||||
from .core.models import HostsFile
 | 
					from .core.models import HostsFile
 | 
				
			||||||
| 
						 | 
					@ -73,6 +74,8 @@ class HostsManagerApp(App):
 | 
				
			||||||
    #entries-table .datatable--odd-row {
 | 
					    #entries-table .datatable--odd-row {
 | 
				
			||||||
        background: $surface;
 | 
					        background: $surface;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    /* DataTable row styling - colors are now handled via Rich Text objects */
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    BINDINGS = [
 | 
					    BINDINGS = [
 | 
				
			||||||
| 
						 | 
					@ -180,10 +183,15 @@ 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:
 | 
				
			||||||
                table.add_row(entry.ip_address, canonical_hostname)
 | 
					                # Active entries in green
 | 
				
			||||||
 | 
					                ip_text = Text(entry.ip_address, style="green")
 | 
				
			||||||
 | 
					                hostname_text = Text(canonical_hostname, style="green")
 | 
				
			||||||
 | 
					                table.add_row(ip_text, hostname_text)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                # For inactive entries, we'll style them differently
 | 
					                # Inactive entries in yellow/orange with # prefix and italic
 | 
				
			||||||
                table.add_row(f"# {entry.ip_address}", canonical_hostname)
 | 
					                ip_text = Text(f"# {entry.ip_address}", style="yellow italic")
 | 
				
			||||||
 | 
					                hostname_text = Text(canonical_hostname, style="yellow italic")
 | 
				
			||||||
 | 
					                table.add_row(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