Coverage for src/utils/console_helpers.py: 52%

52 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-05-25 13:51 -0400

1# Copyright (c) CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL 

2# Unauthorized copying of this file and/or project, via any medium is strictly prohibited. 

3# Direct all questions to legal@cloudzero.com 

4 

5""" 

6Console output utilities for standardized messaging and formatting. 

7Provides consistent console output patterns across the codebase. 

8""" 

9 

10from rich.console import Console 

11from rich.prompt import Prompt, IntPrompt, Confirm 

12from typing import List, Any 

13 

14console = Console() 

15 

16 

17def print_info(message: str) -> None: 

18 """Print an informational message.""" 

19 console.print(f"ℹ️ [cyan]{message}[/cyan]") 

20 

21 

22def print_success(message: str) -> None: 

23 """Print a success message.""" 

24 console.print(f"✅ [green]{message}[/green]") 

25 

26 

27def print_warning(message: str) -> None: 

28 """Print a warning message.""" 

29 console.print(f"⚠️ [yellow]{message}[/yellow]") 

30 

31 

32def print_error(message: str) -> None: 

33 """Print an error message.""" 

34 console.print(f"❌ [red]{message}[/red]") 

35 

36 

37def print_step(step_num: int, message: str) -> None: 

38 """Print a numbered step message.""" 

39 console.print(f"📋 [bold cyan]Step {step_num}:[/bold cyan] {message}") 

40 

41 

42def print_progress(message: str) -> None: 

43 """Print a progress message.""" 

44 console.print(f"🔍 [dim]{message}[/dim]") 

45 

46 

47def print_analysis_header(title: str) -> None: 

48 """Print an analysis section header.""" 

49 console.print(f"\n📊 [bold]{title}[/bold]") 

50 

51 

52def print_section_divider() -> None: 

53 """Print a visual section divider.""" 

54 console.print("\n" + "─" * 60) 

55 

56 

57def print_file_info(filename: str, size_mb: float, rows: int, cols: int) -> None: 

58 """Print standardized file information.""" 

59 console.print(f"📁 [cyan]{filename}[/cyan] ({size_mb:.1f}MB, {rows:,} rows, {cols} columns)") 

60 

61 

62def print_data_summary(total_rows: int, valid_rows: int, excluded_rows: int) -> None: 

63 """Print standardized data quality summary.""" 

64 console.print( 

65 f"📊 [dim]Total rows: {total_rows:,} | Valid: {valid_rows:,} | Excluded: {excluded_rows:,}[/dim]" 

66 ) 

67 

68 

69def print_optimization_info(columns: List[str], limit: int = 5) -> None: 

70 """Print column optimization information.""" 

71 displayed_cols = columns[:limit] 

72 suffix = "..." if len(columns) > limit else "" 

73 console.print( 

74 f"🚀 [green]Optimizing for {len(columns)} columns: {', '.join(displayed_cols)}{suffix}[/green]" 

75 ) 

76 

77 

78def print_schema_cache_info(filename: str) -> None: 

79 """Print schema cache usage information.""" 

80 console.print(f"📋 [green]Using cached schema for {filename} from manifest[/green]") 

81 

82 

83def prompt_with_ctrl_c_reminder(prompt_text: str, **kwargs) -> str: 

84 """Prompt with Ctrl+C reminder.""" 

85 reminder = "[dim](Press Ctrl+C to quit anytime)[/dim]" 

86 enhanced_prompt = f"{prompt_text}\n{reminder}" 

87 return Prompt.ask(enhanced_prompt, **kwargs) 

88 

89 

90def int_prompt_with_ctrl_c_reminder(prompt_text: str, **kwargs) -> int: 

91 """Integer prompt with Ctrl+C reminder.""" 

92 reminder = "[dim](Press Ctrl+C to quit anytime)[/dim]" 

93 enhanced_prompt = f"{prompt_text}\n{reminder}" 

94 return IntPrompt.ask(enhanced_prompt, **kwargs) 

95 

96 

97def confirm_with_ctrl_c_reminder(prompt_text: str, **kwargs) -> bool: 

98 """Confirmation prompt with Ctrl+C reminder.""" 

99 reminder = "[dim](Press Ctrl+C to quit anytime)[/dim]" 

100 enhanced_prompt = f"{prompt_text}\n{reminder}" 

101 return Confirm.ask(enhanced_prompt, **kwargs) 

102 

103 

104def print_config_usage(field_name: str, value: Any) -> None: 

105 """Print configuration usage message.""" 

106 console.print(f"🤖 [cyan]Using configured {field_name}: {value}[/cyan]") 

107 

108 

109def print_config_warning(field_name: str, value: str, reason: str) -> None: 

110 """Print configuration warning message.""" 

111 console.print( 

112 f"⚠️ [yellow]Configured {field_name} '{value}' {reason}. Using interactive mode.[/yellow]" 

113 ) 

114 

115 

116def print_telemetry_tip(message: str) -> None: 

117 """Print a telemetry-specific tip.""" 

118 console.print(f"💡 [yellow]Tip: {message}[/yellow]") 

119 

120 

121def print_analysis_complete() -> None: 

122 """Print analysis completion message.""" 

123 console.print("\n✨ [green]Analysis complete![/green]") 

124 

125 

126def print_interrupted() -> None: 

127 """Print user interruption message.""" 

128 console.print("\n\n👋 [yellow]Analysis interrupted by user. Goodbye![/yellow]")