File size: 6,929 Bytes
46df5f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
"""
Interactive template selector for conference presets.

Provides a terminal UI for selecting a conference template
with information about requirements and rules.
"""
from typing import Optional

from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich.prompt import Prompt
from rich.columns import Columns
from rich.text import Text

from ..templates.base_template import (
    ConferenceTemplate, 
    get_template, 
    get_all_templates,
    ConferenceField
)


class TemplateSelector:
    """Interactive terminal selector for conference templates."""
    
    def __init__(self):
        self.console = Console()
        self.templates = get_all_templates()
    
    def display_templates(self):
        """Display all available templates grouped by field."""
        self.console.clear()
        
        # Header
        self.console.print(Panel(
            "[bold blue]🎓 Conference Template Selector[/bold blue]\n"
            "[dim]Choose a conference template for submission checks[/dim]",
            border_style="blue"
        ))
        self.console.print()
        
        # Group by field
        fields = {
            ConferenceField.NLP: ("🗣️ NLP Conferences", []),
            ConferenceField.CV: ("👁️ Computer Vision Conferences", []),
            ConferenceField.ML: ("🧠 Machine Learning Conferences", []),
        }
        
        for template in self.templates.values():
            fields[template.field][1].append(template)
        
        # Display each field
        for field_enum, (title, templates) in fields.items():
            self.console.print(f"[bold cyan]{title}[/bold cyan]")
            
            table = Table(show_header=True, header_style="bold", box=None, padding=(0, 2))
            table.add_column("ID", style="yellow", width=10)
            table.add_column("Conference", width=15)
            table.add_column("Pages", width=12)
            table.add_column("Key Requirements", style="dim")
            
            for template in templates:
                pages = f"{template.page_limit_review}{template.page_limit_camera}"
                requirements = []
                if template.mandatory_sections:
                    requirements.append(f"Required: {', '.join(template.mandatory_sections)}")
                if template.extra_rules:
                    first_rule = list(template.extra_rules.values())[0]
                    requirements.append(first_rule[:50])
                
                table.add_row(
                    template.short_name,
                    template.name,
                    pages,
                    " | ".join(requirements) if requirements else "Standard format"
                )
            
            self.console.print(table)
            self.console.print()
    
    def display_template_details(self, template: ConferenceTemplate):
        """Display detailed information about a template."""
        self.console.print()
        self.console.print(Panel(
            f"[bold]{template.name}[/bold]",
            border_style="cyan"
        ))
        
        # Basic info
        info = Table(show_header=False, box=None, padding=(0, 2))
        info.add_column("Label", style="dim")
        info.add_column("Value")
        
        info.add_row("Style Package", f"[cyan]{template.style_package}[/cyan]")
        info.add_row("Page Limit (Review)", f"[yellow]{template.page_limit_review}[/yellow] pages")
        info.add_row("Page Limit (Camera)", f"[green]{template.page_limit_camera}[/green] pages")
        info.add_row("Double-Blind", "✓ Yes" if template.double_blind else "✗ No")
        
        if template.mandatory_sections:
            info.add_row("Mandatory Sections", ", ".join(template.mandatory_sections))
        if template.optional_sections:
            info.add_row("Optional Sections", ", ".join(template.optional_sections))
        
        self.console.print(info)
        
        # Extra rules
        if template.extra_rules:
            self.console.print()
            self.console.print("[bold]Special Requirements:[/bold]")
            for key, value in template.extra_rules.items():
                self.console.print(f"  • [dim]{key}:[/dim] {value}")
        
        self.console.print()
    
    def run(self) -> Optional[ConferenceTemplate]:
        """Run the interactive selector and return the chosen template."""
        while True:
            self.display_templates()
            
            # Get user input
            choice = Prompt.ask(
                "[bold]Enter template ID (or 'q' to quit, 'd <id>' for details)[/bold]",
                default="q"
            )
            
            if choice.lower() == 'q':
                return None
            
            # Handle details command
            if choice.lower().startswith('d '):
                template_id = choice[2:].strip().lower()
                template = get_template(template_id)
                if template:
                    self.display_template_details(template)
                    Prompt.ask("Press Enter to continue")
                else:
                    self.console.print(f"[red]Unknown template: {template_id}[/red]")
                    Prompt.ask("Press Enter to continue")
                continue
            
            # Try to get template
            template = get_template(choice)
            if template:
                self.console.print(f"[green]✓ Selected: {template.name}[/green]")
                return template
            else:
                self.console.print(f"[red]Unknown template: {choice}[/red]")
                self.console.print("[dim]Available: " + ", ".join(self.templates.keys()) + "[/dim]")
                Prompt.ask("Press Enter to continue")


def launch_template_selector() -> Optional[ConferenceTemplate]:
    """Launch the template selector and return the chosen template."""
    selector = TemplateSelector()
    return selector.run()


def list_templates(console: Console = None):
    """Print a simple list of available templates."""
    if console is None:
        console = Console()
    
    console.print("\n[bold]Available Conference Templates:[/bold]\n")
    
    templates = get_all_templates()
    
    # Group by field
    by_field = {}
    for t in templates.values():
        if t.field not in by_field:
            by_field[t.field] = []
        by_field[t.field].append(t)
    
    field_names = {
        ConferenceField.NLP: "NLP",
        ConferenceField.CV: "Computer Vision",
        ConferenceField.ML: "Machine Learning",
    }
    
    for field, field_templates in by_field.items():
        console.print(f"[cyan]{field_names[field]}:[/cyan]")
        for t in field_templates:
            console.print(f"  • [yellow]{t.short_name:8}[/yellow] - {t.name} ({t.page_limit_review}/{t.page_limit_camera} pages)")
    
    console.print()