igntui 0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. igntui/__init__.py +57 -0
  2. igntui/__main__.py +10 -0
  3. igntui/app.py +37 -0
  4. igntui/cli/__init__.py +31 -0
  5. igntui/cli/base.py +104 -0
  6. igntui/cli/commands/__init__.py +17 -0
  7. igntui/cli/commands/cache_cmd.py +95 -0
  8. igntui/cli/commands/generate_cmd.py +85 -0
  9. igntui/cli/commands/list_cmd.py +66 -0
  10. igntui/cli/commands/test_cmd.py +64 -0
  11. igntui/cli/commands/tui_cmd.py +34 -0
  12. igntui/cli/parser.py +162 -0
  13. igntui/cli/setup.py +71 -0
  14. igntui/core/__init__.py +8 -0
  15. igntui/core/api/__init__.py +16 -0
  16. igntui/core/api/client.py +222 -0
  17. igntui/core/api/errors.py +29 -0
  18. igntui/core/api/rate_limiter.py +30 -0
  19. igntui/core/api/request_handler.py +124 -0
  20. igntui/core/api/response.py +16 -0
  21. igntui/core/cache.py +284 -0
  22. igntui/core/config.py +174 -0
  23. igntui/core/search.py +354 -0
  24. igntui/main.py +74 -0
  25. igntui/tui/__init__.py +22 -0
  26. igntui/tui/actions.py +254 -0
  27. igntui/tui/app.py +246 -0
  28. igntui/tui/curses_setup.py +88 -0
  29. igntui/tui/event_handler.py +310 -0
  30. igntui/tui/lifecycle.py +102 -0
  31. igntui/tui/renderer.py +108 -0
  32. igntui/tui/state.py +77 -0
  33. igntui/ui/__init__.py +33 -0
  34. igntui/ui/components/__init__.py +31 -0
  35. igntui/ui/components/base_dialog.py +75 -0
  36. igntui/ui/components/base_panel.py +85 -0
  37. igntui/ui/components/confirm_dialog.py +100 -0
  38. igntui/ui/components/content_panel.py +77 -0
  39. igntui/ui/components/export_dialog.py +139 -0
  40. igntui/ui/components/help_dialog.py +161 -0
  41. igntui/ui/components/save_dialog.py +109 -0
  42. igntui/ui/components/search_panel.py +52 -0
  43. igntui/ui/components/selected_panel.py +107 -0
  44. igntui/ui/components/splash.py +236 -0
  45. igntui/ui/components/status_bar.py +78 -0
  46. igntui/ui/components/templates_panel.py +153 -0
  47. igntui/utils/__init__.py +19 -0
  48. igntui/utils/logging.py +288 -0
  49. igntui-0.0.0.dist-info/METADATA +425 -0
  50. igntui-0.0.0.dist-info/RECORD +52 -0
  51. igntui-0.0.0.dist-info/WHEEL +4 -0
  52. igntui-0.0.0.dist-info/entry_points.txt +4 -0
igntui/tui/app.py ADDED
@@ -0,0 +1,246 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+
5
+ import curses
6
+ import logging
7
+ import time
8
+ from typing import Optional
9
+
10
+ from ..core.api import GitIgnoreAPI
11
+ from ..core.search import SearchManager
12
+ from ..ui import (
13
+ ContentPanel,
14
+ SearchPanel,
15
+ SelectedPanel,
16
+ SplashScreen,
17
+ StatusBar,
18
+ TemplatesPanel,
19
+ )
20
+ from .actions import TUIActions
21
+ from .curses_setup import CursesSetup
22
+ from .event_handler import EventHandler
23
+ from .lifecycle import TemplateLifecycle
24
+ from .renderer import TUIRenderer
25
+ from .state import TUIState
26
+
27
+ logger = logging.getLogger(__name__)
28
+
29
+
30
+ class GitIgnoreTUI:
31
+ def __init__(self, stdscr, show_splash: bool = True):
32
+ self.stdscr = stdscr
33
+ self.show_splash = show_splash
34
+ self.api = GitIgnoreAPI()
35
+ self.search_manager = SearchManager()
36
+ self.state = TUIState()
37
+
38
+ CursesSetup.setup_curses(stdscr)
39
+
40
+ if self.show_splash:
41
+ try:
42
+ splash = SplashScreen(self.stdscr)
43
+ success = splash.show(load_callback=self._load_templates_sync)
44
+ self.state.loading = False
45
+ if success and self.state.templates:
46
+ logger.info(
47
+ f"Splash loaded {len(self.state.templates)} templates successfully"
48
+ )
49
+ except Exception as e:
50
+ logger.warning(f"Could not show splash screen: {e}")
51
+ self.state.loading = False
52
+
53
+ self._init_ui_components()
54
+ self.lifecycle = TemplateLifecycle(self.api, self.search_manager)
55
+ self.actions = TUIActions(self.stdscr, self.state)
56
+ self.event_handler = EventHandler(self.state, self.lifecycle)
57
+ self._setup_event_callbacks()
58
+ self.renderer = TUIRenderer(
59
+ self.stdscr,
60
+ self.state,
61
+ {
62
+ "search_panel": self.search_panel,
63
+ "templates_panel": self.templates_panel,
64
+ "selected_panel": self.selected_panel,
65
+ "content_panel": self.content_panel,
66
+ "status_bar": self.status_bar,
67
+ },
68
+ )
69
+
70
+ if not self.state.templates:
71
+ self._load_templates_async()
72
+
73
+ logger.info("GitIgnoreTUI initialized successfully")
74
+
75
+ def _init_ui_components(self) -> None:
76
+ max_y, max_x = self.stdscr.getmaxyx()
77
+
78
+ try:
79
+ left_width = max_x // 3
80
+ right_width = max_x - left_width
81
+ bottom_height = 6
82
+ search_height = 3
83
+ templates_height = max_y - bottom_height - search_height - 1
84
+
85
+ self.search_panel = SearchPanel(
86
+ self.stdscr, y=0, x=0, height=search_height, width=left_width
87
+ )
88
+
89
+ self.templates_panel = TemplatesPanel(
90
+ self.stdscr,
91
+ y=search_height,
92
+ x=0,
93
+ height=templates_height,
94
+ width=left_width,
95
+ )
96
+
97
+ self.selected_panel = SelectedPanel(
98
+ self.stdscr,
99
+ y=max_y - bottom_height - 1,
100
+ x=0,
101
+ height=bottom_height,
102
+ width=max_x,
103
+ )
104
+
105
+ self.content_panel = ContentPanel(
106
+ self.stdscr,
107
+ y=0,
108
+ x=left_width,
109
+ height=max_y - bottom_height - 1,
110
+ width=right_width,
111
+ )
112
+
113
+ self.status_bar = StatusBar(self.stdscr)
114
+
115
+ logger.debug("UI components initialized")
116
+
117
+ except Exception as e:
118
+ logger.error(f"Error initializing UI components: {e}")
119
+ raise
120
+
121
+ def _setup_event_callbacks(self) -> None:
122
+ self.event_handler.on_quit = self._handle_quit
123
+ self.event_handler.on_help = self.actions.show_help_dialog
124
+ self.event_handler.on_info = self.actions.show_info_dialog
125
+ self.event_handler.on_save = self.actions.save_gitignore
126
+ self.event_handler.on_export = self.actions.export_templates
127
+ self.event_handler.on_refresh = self._load_templates_async
128
+ self.event_handler.on_generate = self._generate_content_async
129
+
130
+ def _handle_quit(self) -> None:
131
+ self.state.running = False
132
+ logger.info("Quit requested")
133
+
134
+ def _load_templates_sync(self) -> tuple:
135
+ try:
136
+ response = self.api.list_templates()
137
+ if response.success and response.data:
138
+ templates = response.data
139
+ self.state.templates = templates
140
+ self.state.filtered_templates = templates[:]
141
+ logger.info(f"Loaded {len(templates)} templates during splash")
142
+ return (True, len(templates), "")
143
+ else:
144
+ error_msg = response.error_message or "No templates returned from API"
145
+ return (False, 0, error_msg)
146
+ except Exception as e:
147
+ error_msg = f"Failed to load templates: {e}"
148
+ logger.error(error_msg, exc_info=True)
149
+ return (False, 0, error_msg)
150
+
151
+ def _load_templates_async(self) -> None:
152
+ self.state.loading = True
153
+ self.state.set_status_message("Loading templates...")
154
+
155
+ def on_success(templates):
156
+ self.state.templates = templates
157
+ self.state.filtered_templates = templates[:]
158
+ self.state.set_status_message(f"✓ Loaded {len(templates)} templates")
159
+
160
+ def on_error(error_msg):
161
+ self.state.set_status_message(error_msg, is_error=True)
162
+
163
+ def on_complete():
164
+ self.state.loading = False
165
+
166
+ self.lifecycle.load_templates_async(on_success, on_error, on_complete)
167
+
168
+ def _generate_content_async(self) -> None:
169
+ if not self.state.selected_templates:
170
+ self.state.generated_content = "# No templates selected\n# Select templates from the Available Templates panel"
171
+ return
172
+
173
+ self.state.generation_in_progress = True
174
+ selected_list = self.state.get_selected_templates_list()
175
+ self.state.set_status_message(
176
+ f"Generating content for {len(selected_list)} templates..."
177
+ )
178
+
179
+ def on_success(content, from_cache):
180
+ self.state.generated_content = content
181
+ cache_info = " (cached)" if from_cache else ""
182
+ self.state.set_status_message(
183
+ f"✓ Generated content for {len(selected_list)} templates{cache_info}"
184
+ )
185
+
186
+ def on_error(error_msg):
187
+ self.state.generated_content = f"# Error generating content: {error_msg}\n# Selected templates: {selected_list}"
188
+ self.state.set_status_message(error_msg, is_error=True)
189
+
190
+ def on_complete():
191
+ self.state.generation_in_progress = False
192
+
193
+ self.lifecycle.generate_content_async(
194
+ selected_list, on_success, on_error, on_complete
195
+ )
196
+
197
+ def run(self) -> int:
198
+ logger.info("Starting TUI main loop")
199
+
200
+ try:
201
+ while self.state.running:
202
+ self.state.clear_status_message()
203
+ self.renderer.render()
204
+
205
+ try:
206
+ key = self.stdscr.getch()
207
+ if key != -1:
208
+ should_continue = self.event_handler.handle_input(key)
209
+ if not should_continue:
210
+ break
211
+ except curses.error:
212
+ pass
213
+
214
+ time.sleep(0.01)
215
+
216
+ logger.info("TUI main loop ended normally")
217
+ return 0
218
+
219
+ except KeyboardInterrupt:
220
+ logger.info("TUI interrupted by user")
221
+ return 0
222
+ except Exception as e:
223
+ logger.error(f"Error in TUI main loop: {e}", exc_info=True)
224
+ return 1
225
+ finally:
226
+ CursesSetup.cleanup(self.stdscr)
227
+
228
+
229
+ def main() -> int:
230
+ try:
231
+ exit_code = curses.wrapper(lambda stdscr: GitIgnoreTUI(stdscr).run())
232
+ print("\n✓ igntui closed successfully")
233
+ return exit_code
234
+ except KeyboardInterrupt:
235
+ print("\n✓ igntui interrupted by user")
236
+ return 0
237
+ except Exception as e:
238
+ print(f"\n✗ Error running igntui: {e}")
239
+ logger.error(f"Fatal error: {e}", exc_info=True)
240
+ return 1
241
+
242
+
243
+ if __name__ == "__main__":
244
+ import sys
245
+
246
+ sys.exit(main())
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+
5
+ import curses
6
+ from typing import Optional
7
+
8
+
9
+ class CursesSetup:
10
+ COLOR_BORDER = 1
11
+ COLOR_HIGHLIGHT = 2
12
+ COLOR_SELECTED = 3
13
+ COLOR_SUCCESS = 4
14
+ COLOR_STATUS_BAR = 5
15
+ COLOR_TITLE = 6
16
+ COLOR_ERROR = 7
17
+ COLOR_NORMAL = 8
18
+
19
+ @staticmethod
20
+ def setup_curses(stdscr) -> None:
21
+ curses.curs_set(0)
22
+ stdscr.keypad(True)
23
+ stdscr.timeout(100)
24
+ CursesSetup.setup_colors()
25
+
26
+ @staticmethod
27
+ def setup_colors() -> None:
28
+ if not curses.has_colors():
29
+ return
30
+
31
+ curses.start_color()
32
+ curses.use_default_colors()
33
+ curses.init_pair(CursesSetup.COLOR_BORDER, curses.COLOR_CYAN, -1)
34
+ curses.init_pair(CursesSetup.COLOR_HIGHLIGHT, curses.COLOR_YELLOW, -1)
35
+ curses.init_pair(
36
+ CursesSetup.COLOR_SELECTED, curses.COLOR_BLACK, curses.COLOR_CYAN
37
+ )
38
+ curses.init_pair(CursesSetup.COLOR_SUCCESS, curses.COLOR_GREEN, -1)
39
+ curses.init_pair(CursesSetup.COLOR_STATUS_BAR, curses.COLOR_GREEN, -1)
40
+ curses.init_pair(CursesSetup.COLOR_TITLE, curses.COLOR_MAGENTA, -1)
41
+ curses.init_pair(CursesSetup.COLOR_ERROR, curses.COLOR_RED, -1)
42
+ curses.init_pair(CursesSetup.COLOR_NORMAL, curses.COLOR_WHITE, -1)
43
+
44
+ @staticmethod
45
+ def get_color_pair(color_id: int) -> int:
46
+ return curses.color_pair(color_id)
47
+
48
+ @staticmethod
49
+ def cleanup(stdscr: Optional = None) -> None:
50
+ try:
51
+ if stdscr:
52
+ stdscr.keypad(False)
53
+ curses.curs_set(1)
54
+ curses.endwin()
55
+ except:
56
+ pass
57
+
58
+
59
+ def get_border_color() -> int:
60
+ return CursesSetup.get_color_pair(CursesSetup.COLOR_BORDER)
61
+
62
+
63
+ def get_highlight_color() -> int:
64
+ return CursesSetup.get_color_pair(CursesSetup.COLOR_HIGHLIGHT)
65
+
66
+
67
+ def get_selected_color() -> int:
68
+ return CursesSetup.get_color_pair(CursesSetup.COLOR_SELECTED)
69
+
70
+
71
+ def get_success_color() -> int:
72
+ return CursesSetup.get_color_pair(CursesSetup.COLOR_SUCCESS)
73
+
74
+
75
+ def get_status_bar_color() -> int:
76
+ return CursesSetup.get_color_pair(CursesSetup.COLOR_STATUS_BAR)
77
+
78
+
79
+ def get_title_color() -> int:
80
+ return CursesSetup.get_color_pair(CursesSetup.COLOR_TITLE)
81
+
82
+
83
+ def get_error_color() -> int:
84
+ return CursesSetup.get_color_pair(CursesSetup.COLOR_ERROR)
85
+
86
+
87
+ def get_normal_color() -> int:
88
+ return CursesSetup.get_color_pair(CursesSetup.COLOR_NORMAL)
@@ -0,0 +1,310 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+
5
+ import curses
6
+ import logging
7
+ from typing import Callable, Optional
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ class EventHandler:
13
+ def __init__(self, state, lifecycle):
14
+ self.state = state
15
+ self.lifecycle = lifecycle
16
+ self.on_quit: Optional[Callable[[], None]] = None
17
+ self.on_help: Optional[Callable[[], None]] = None
18
+ self.on_info: Optional[Callable[[], None]] = None
19
+ self.on_save: Optional[Callable[[], None]] = None
20
+ self.on_export: Optional[Callable[[], None]] = None
21
+ self.on_refresh: Optional[Callable[[], None]] = None
22
+ self.on_generate: Optional[Callable[[], None]] = None
23
+
24
+ def handle_input(self, key: int) -> bool:
25
+ if key == curses.KEY_F1:
26
+ self.state.current_search_mode = "fuzzy"
27
+ self._apply_filter()
28
+ self.state.set_status_message(f"Search mode: FUZZY")
29
+ return True
30
+
31
+ elif key == curses.KEY_F2:
32
+ self.state.current_search_mode = "exact"
33
+ self._apply_filter()
34
+ self.state.set_status_message(f"Search mode: EXACT")
35
+ return True
36
+
37
+ elif key == curses.KEY_F3:
38
+ self.state.current_search_mode = "regex"
39
+ self._apply_filter()
40
+ self.state.set_status_message(f"Search mode: REGEX")
41
+ return True
42
+
43
+ elif key == curses.KEY_F5:
44
+ if self.on_refresh:
45
+ self.on_refresh()
46
+ return True
47
+
48
+ elif key == curses.KEY_F12:
49
+ if self.on_help:
50
+ self.on_help()
51
+ return True
52
+
53
+ if key in (ord("q"), ord("Q"), 27):
54
+ if self.state.current_panel != 0:
55
+ if self.on_quit:
56
+ self.on_quit()
57
+ return False
58
+ else:
59
+ if key == ord("q") or key == ord("Q"):
60
+ self._handle_search_input(key)
61
+ return True
62
+
63
+ if key == ord("\t"):
64
+ self.state.current_panel = (self.state.current_panel + 1) % 4
65
+ return True
66
+
67
+ elif key == 353:
68
+ self.state.current_panel = (self.state.current_panel - 1) % 4
69
+ return True
70
+
71
+ if self.state.current_panel == 0:
72
+ return self._handle_search_input(key)
73
+
74
+ if key == ord("i"):
75
+ if self.on_info:
76
+ self.on_info()
77
+ return True
78
+
79
+ elif key == ord("h") or key == ord("?"):
80
+ if self.on_help:
81
+ self.on_help()
82
+ return True
83
+
84
+ elif key == ord("s"):
85
+ if self.on_save:
86
+ self.on_save()
87
+ return True
88
+
89
+ elif key == ord("e"):
90
+ if self.on_export:
91
+ self.on_export()
92
+ return True
93
+
94
+ elif key == ord("r"):
95
+ if self.on_refresh:
96
+ self.on_refresh()
97
+ return True
98
+
99
+ elif key == ord("c"):
100
+ self.state.clear_all_selections()
101
+ self.state.generated_content = ""
102
+ self.state.set_status_message("Cleared all selections")
103
+ return True
104
+
105
+ elif key == ord("/"):
106
+ self.state.current_panel = 0
107
+ self.state.set_status_message("Search mode - Type to filter templates")
108
+ return True
109
+
110
+ elif key == ord("a"):
111
+ self._select_all_visible()
112
+ return True
113
+
114
+ elif key == ord("x"):
115
+ self._remove_all_visible()
116
+ return True
117
+
118
+ elif key == curses.KEY_UP:
119
+ self._handle_up()
120
+ return True
121
+
122
+ elif key == curses.KEY_DOWN:
123
+ self._handle_down()
124
+ return True
125
+
126
+ elif key == curses.KEY_PPAGE:
127
+ self._handle_page_up()
128
+ return True
129
+
130
+ elif key == curses.KEY_NPAGE:
131
+ self._handle_page_down()
132
+ return True
133
+
134
+ elif key == curses.KEY_HOME:
135
+ self._handle_home()
136
+ return True
137
+
138
+ elif key == curses.KEY_END:
139
+ self._handle_end()
140
+ return True
141
+
142
+ elif key in (ord(" "), ord("\n"), ord("\r")):
143
+ self._handle_selection()
144
+ return True
145
+
146
+ return True
147
+
148
+ def _handle_search_input(self, key: int) -> bool:
149
+ if key in (8, 127):
150
+ if self.state.filter_text:
151
+ self.state.filter_text = self.state.filter_text[:-1]
152
+ self._apply_filter()
153
+ self.state.reset_template_selection()
154
+
155
+ elif key == 21:
156
+ self.state.filter_text = ""
157
+ self._apply_filter()
158
+ self.state.reset_template_selection()
159
+ self.state.set_status_message("Search cleared")
160
+
161
+ elif 32 <= key <= 126:
162
+ char = chr(key)
163
+ self.state.filter_text += char
164
+ self._apply_filter()
165
+ self.state.reset_template_selection()
166
+
167
+ return True
168
+
169
+ def _apply_filter(self) -> None:
170
+ self.state.filtered_templates = self.lifecycle.filter_templates(
171
+ self.state.templates, self.state.filter_text, self.state.current_search_mode
172
+ )
173
+
174
+ def _select_all_visible(self) -> None:
175
+ if not self.state.filtered_templates:
176
+ return
177
+
178
+ added_count = 0
179
+ for template in self.state.filtered_templates:
180
+ if template not in self.state.selected_templates:
181
+ self.state.selected_templates.add(template)
182
+ added_count += 1
183
+
184
+ if added_count > 0:
185
+ self.state.set_status_message(f"Added {added_count} templates")
186
+ if self.on_generate:
187
+ self.on_generate()
188
+ else:
189
+ self.state.set_status_message("All visible templates already selected")
190
+
191
+ def _remove_all_visible(self) -> None:
192
+ if not self.state.filtered_templates:
193
+ return
194
+
195
+ removed_count = 0
196
+ for template in self.state.filtered_templates:
197
+ if template in self.state.selected_templates:
198
+ self.state.selected_templates.remove(template)
199
+ removed_count += 1
200
+
201
+ if removed_count > 0:
202
+ self.state.set_status_message(f"Removed {removed_count} templates")
203
+ if self.on_generate:
204
+ self.on_generate()
205
+ else:
206
+ self.state.set_status_message("No visible templates were selected")
207
+
208
+ def _handle_up(self) -> None:
209
+ if self.state.current_panel == 1:
210
+ self.state.template_selected = max(0, self.state.template_selected - 1)
211
+ elif self.state.current_panel == 2:
212
+ self.state.selected_index = max(0, self.state.selected_index - 1)
213
+ elif self.state.current_panel == 3:
214
+ self.state.content_scroll = max(0, self.state.content_scroll - 1)
215
+
216
+ def _handle_down(self) -> None:
217
+ if self.state.current_panel == 1:
218
+ display_templates = self.state.get_display_templates()
219
+ if display_templates:
220
+ self.state.template_selected = min(
221
+ len(display_templates) - 1, self.state.template_selected + 1
222
+ )
223
+ elif self.state.current_panel == 2:
224
+ selected_count = self.state.get_selection_count()
225
+ if selected_count > 0:
226
+ self.state.selected_index = min(
227
+ selected_count - 1, self.state.selected_index + 1
228
+ )
229
+ elif self.state.current_panel == 3:
230
+ content_lines = len(self.state.generated_content.split("\n"))
231
+ self.state.content_scroll = min(
232
+ max(0, content_lines - 10), self.state.content_scroll + 1
233
+ )
234
+
235
+ def _handle_page_up(self) -> None:
236
+ if self.state.current_panel == 1:
237
+ self.state.template_selected = max(0, self.state.template_selected - 10)
238
+ elif self.state.current_panel == 2:
239
+ self.state.selected_index = max(0, self.state.selected_index - 10)
240
+ elif self.state.current_panel == 3:
241
+ self.state.content_scroll = max(0, self.state.content_scroll - 10)
242
+
243
+ def _handle_page_down(self) -> None:
244
+ if self.state.current_panel == 1:
245
+ display_templates = self.state.get_display_templates()
246
+ if display_templates:
247
+ self.state.template_selected = min(
248
+ len(display_templates) - 1, self.state.template_selected + 10
249
+ )
250
+ elif self.state.current_panel == 2:
251
+ selected_count = self.state.get_selection_count()
252
+ if selected_count > 0:
253
+ self.state.selected_index = min(
254
+ selected_count - 1, self.state.selected_index + 10
255
+ )
256
+ elif self.state.current_panel == 3:
257
+ self.state.content_scroll += 10
258
+
259
+ def _handle_home(self) -> None:
260
+ if self.state.current_panel == 1:
261
+ self.state.reset_template_selection()
262
+ elif self.state.current_panel == 2:
263
+ self.state.reset_selected_panel()
264
+ elif self.state.current_panel == 3:
265
+ self.state.reset_content_scroll()
266
+
267
+ def _handle_end(self) -> None:
268
+ if self.state.current_panel == 1:
269
+ display_templates = self.state.get_display_templates()
270
+ if display_templates:
271
+ self.state.template_selected = len(display_templates) - 1
272
+ elif self.state.current_panel == 2:
273
+ selected_count = self.state.get_selection_count()
274
+ if selected_count > 0:
275
+ self.state.selected_index = selected_count - 1
276
+ elif self.state.current_panel == 3:
277
+ content_lines = len(self.state.generated_content.split("\n"))
278
+ self.state.content_scroll = max(0, content_lines - 10)
279
+
280
+ def _handle_selection(self) -> None:
281
+ if self.state.current_panel == 1:
282
+ display_templates = self.state.get_display_templates()
283
+ if display_templates and self.state.template_selected < len(
284
+ display_templates
285
+ ):
286
+ template = display_templates[self.state.template_selected]
287
+ self.state.toggle_template_selection(template)
288
+
289
+ if template in self.state.selected_templates:
290
+ self.state.set_status_message(f"Added: {template}")
291
+ else:
292
+ self.state.set_status_message(f"Removed: {template}")
293
+
294
+ if self.on_generate:
295
+ self.on_generate()
296
+
297
+ elif self.state.current_panel == 2:
298
+ selected_list = self.state.get_selected_templates_list()
299
+ if selected_list and self.state.selected_index < len(selected_list):
300
+ template_to_remove = selected_list[self.state.selected_index]
301
+ self.state.selected_templates.remove(template_to_remove)
302
+ self.state.set_status_message(f"Removed: {template_to_remove}")
303
+
304
+ if self.state.selected_index >= self.state.get_selection_count():
305
+ self.state.selected_index = max(
306
+ 0, self.state.get_selection_count() - 1
307
+ )
308
+
309
+ if self.on_generate:
310
+ self.on_generate()