pomera-ai-commander 0.1.0 → 1.2.1

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 (191) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +105 -680
  3. package/bin/pomera-ai-commander.js +62 -62
  4. package/core/__init__.py +65 -65
  5. package/core/app_context.py +482 -482
  6. package/core/async_text_processor.py +421 -421
  7. package/core/backup_manager.py +655 -655
  8. package/core/backup_recovery_manager.py +1033 -1033
  9. package/core/content_hash_cache.py +508 -508
  10. package/core/context_menu.py +313 -313
  11. package/core/data_validator.py +1066 -1066
  12. package/core/database_connection_manager.py +744 -744
  13. package/core/database_curl_settings_manager.py +608 -608
  14. package/core/database_promera_ai_settings_manager.py +446 -446
  15. package/core/database_schema.py +411 -411
  16. package/core/database_schema_manager.py +395 -395
  17. package/core/database_settings_manager.py +1507 -1507
  18. package/core/database_settings_manager_interface.py +456 -456
  19. package/core/dialog_manager.py +734 -734
  20. package/core/efficient_line_numbers.py +510 -510
  21. package/core/error_handler.py +746 -746
  22. package/core/error_service.py +431 -431
  23. package/core/event_consolidator.py +511 -511
  24. package/core/mcp/__init__.py +43 -43
  25. package/core/mcp/protocol.py +288 -288
  26. package/core/mcp/schema.py +251 -251
  27. package/core/mcp/server_stdio.py +299 -299
  28. package/core/mcp/tool_registry.py +2372 -2345
  29. package/core/memory_efficient_text_widget.py +711 -711
  30. package/core/migration_manager.py +914 -914
  31. package/core/migration_test_suite.py +1085 -1085
  32. package/core/migration_validator.py +1143 -1143
  33. package/core/optimized_find_replace.py +714 -714
  34. package/core/optimized_pattern_engine.py +424 -424
  35. package/core/optimized_search_highlighter.py +552 -552
  36. package/core/performance_monitor.py +674 -674
  37. package/core/persistence_manager.py +712 -712
  38. package/core/progressive_stats_calculator.py +632 -632
  39. package/core/regex_pattern_cache.py +529 -529
  40. package/core/regex_pattern_library.py +350 -350
  41. package/core/search_operation_manager.py +434 -434
  42. package/core/settings_defaults_registry.py +1087 -1087
  43. package/core/settings_integrity_validator.py +1111 -1111
  44. package/core/settings_serializer.py +557 -557
  45. package/core/settings_validator.py +1823 -1823
  46. package/core/smart_stats_calculator.py +709 -709
  47. package/core/statistics_update_manager.py +619 -619
  48. package/core/stats_config_manager.py +858 -858
  49. package/core/streaming_text_handler.py +723 -723
  50. package/core/task_scheduler.py +596 -596
  51. package/core/update_pattern_library.py +168 -168
  52. package/core/visibility_monitor.py +596 -596
  53. package/core/widget_cache.py +498 -498
  54. package/mcp.json +51 -61
  55. package/package.json +61 -57
  56. package/pomera.py +7482 -7482
  57. package/pomera_mcp_server.py +183 -144
  58. package/requirements.txt +32 -0
  59. package/tools/__init__.py +4 -4
  60. package/tools/ai_tools.py +2891 -2891
  61. package/tools/ascii_art_generator.py +352 -352
  62. package/tools/base64_tools.py +183 -183
  63. package/tools/base_tool.py +511 -511
  64. package/tools/case_tool.py +308 -308
  65. package/tools/column_tools.py +395 -395
  66. package/tools/cron_tool.py +884 -884
  67. package/tools/curl_history.py +600 -600
  68. package/tools/curl_processor.py +1207 -1207
  69. package/tools/curl_settings.py +502 -502
  70. package/tools/curl_tool.py +5467 -5467
  71. package/tools/diff_viewer.py +1071 -1071
  72. package/tools/email_extraction_tool.py +248 -248
  73. package/tools/email_header_analyzer.py +425 -425
  74. package/tools/extraction_tools.py +250 -250
  75. package/tools/find_replace.py +1750 -1750
  76. package/tools/folder_file_reporter.py +1463 -1463
  77. package/tools/folder_file_reporter_adapter.py +480 -480
  78. package/tools/generator_tools.py +1216 -1216
  79. package/tools/hash_generator.py +255 -255
  80. package/tools/html_tool.py +656 -656
  81. package/tools/jsonxml_tool.py +729 -729
  82. package/tools/line_tools.py +419 -419
  83. package/tools/markdown_tools.py +561 -561
  84. package/tools/mcp_widget.py +1417 -1417
  85. package/tools/notes_widget.py +973 -973
  86. package/tools/number_base_converter.py +372 -372
  87. package/tools/regex_extractor.py +571 -571
  88. package/tools/slug_generator.py +310 -310
  89. package/tools/sorter_tools.py +458 -458
  90. package/tools/string_escape_tool.py +392 -392
  91. package/tools/text_statistics_tool.py +365 -365
  92. package/tools/text_wrapper.py +430 -430
  93. package/tools/timestamp_converter.py +421 -421
  94. package/tools/tool_loader.py +710 -710
  95. package/tools/translator_tools.py +522 -522
  96. package/tools/url_link_extractor.py +261 -261
  97. package/tools/url_parser.py +204 -204
  98. package/tools/whitespace_tools.py +355 -355
  99. package/tools/word_frequency_counter.py +146 -146
  100. package/core/__pycache__/__init__.cpython-313.pyc +0 -0
  101. package/core/__pycache__/app_context.cpython-313.pyc +0 -0
  102. package/core/__pycache__/async_text_processor.cpython-313.pyc +0 -0
  103. package/core/__pycache__/backup_manager.cpython-313.pyc +0 -0
  104. package/core/__pycache__/backup_recovery_manager.cpython-313.pyc +0 -0
  105. package/core/__pycache__/content_hash_cache.cpython-313.pyc +0 -0
  106. package/core/__pycache__/context_menu.cpython-313.pyc +0 -0
  107. package/core/__pycache__/data_validator.cpython-313.pyc +0 -0
  108. package/core/__pycache__/database_connection_manager.cpython-313.pyc +0 -0
  109. package/core/__pycache__/database_curl_settings_manager.cpython-313.pyc +0 -0
  110. package/core/__pycache__/database_promera_ai_settings_manager.cpython-313.pyc +0 -0
  111. package/core/__pycache__/database_schema.cpython-313.pyc +0 -0
  112. package/core/__pycache__/database_schema_manager.cpython-313.pyc +0 -0
  113. package/core/__pycache__/database_settings_manager.cpython-313.pyc +0 -0
  114. package/core/__pycache__/database_settings_manager_interface.cpython-313.pyc +0 -0
  115. package/core/__pycache__/dialog_manager.cpython-313.pyc +0 -0
  116. package/core/__pycache__/efficient_line_numbers.cpython-313.pyc +0 -0
  117. package/core/__pycache__/error_handler.cpython-313.pyc +0 -0
  118. package/core/__pycache__/error_service.cpython-313.pyc +0 -0
  119. package/core/__pycache__/event_consolidator.cpython-313.pyc +0 -0
  120. package/core/__pycache__/memory_efficient_text_widget.cpython-313.pyc +0 -0
  121. package/core/__pycache__/migration_manager.cpython-313.pyc +0 -0
  122. package/core/__pycache__/migration_test_suite.cpython-313.pyc +0 -0
  123. package/core/__pycache__/migration_validator.cpython-313.pyc +0 -0
  124. package/core/__pycache__/optimized_find_replace.cpython-313.pyc +0 -0
  125. package/core/__pycache__/optimized_pattern_engine.cpython-313.pyc +0 -0
  126. package/core/__pycache__/optimized_search_highlighter.cpython-313.pyc +0 -0
  127. package/core/__pycache__/performance_monitor.cpython-313.pyc +0 -0
  128. package/core/__pycache__/persistence_manager.cpython-313.pyc +0 -0
  129. package/core/__pycache__/progressive_stats_calculator.cpython-313.pyc +0 -0
  130. package/core/__pycache__/regex_pattern_cache.cpython-313.pyc +0 -0
  131. package/core/__pycache__/regex_pattern_library.cpython-313.pyc +0 -0
  132. package/core/__pycache__/search_operation_manager.cpython-313.pyc +0 -0
  133. package/core/__pycache__/settings_defaults_registry.cpython-313.pyc +0 -0
  134. package/core/__pycache__/settings_integrity_validator.cpython-313.pyc +0 -0
  135. package/core/__pycache__/settings_serializer.cpython-313.pyc +0 -0
  136. package/core/__pycache__/settings_validator.cpython-313.pyc +0 -0
  137. package/core/__pycache__/smart_stats_calculator.cpython-313.pyc +0 -0
  138. package/core/__pycache__/statistics_update_manager.cpython-313.pyc +0 -0
  139. package/core/__pycache__/stats_config_manager.cpython-313.pyc +0 -0
  140. package/core/__pycache__/streaming_text_handler.cpython-313.pyc +0 -0
  141. package/core/__pycache__/task_scheduler.cpython-313.pyc +0 -0
  142. package/core/__pycache__/visibility_monitor.cpython-313.pyc +0 -0
  143. package/core/__pycache__/widget_cache.cpython-313.pyc +0 -0
  144. package/core/mcp/__pycache__/__init__.cpython-313.pyc +0 -0
  145. package/core/mcp/__pycache__/protocol.cpython-313.pyc +0 -0
  146. package/core/mcp/__pycache__/schema.cpython-313.pyc +0 -0
  147. package/core/mcp/__pycache__/server_stdio.cpython-313.pyc +0 -0
  148. package/core/mcp/__pycache__/tool_registry.cpython-313.pyc +0 -0
  149. package/tools/__pycache__/__init__.cpython-313.pyc +0 -0
  150. package/tools/__pycache__/ai_tools.cpython-313.pyc +0 -0
  151. package/tools/__pycache__/ascii_art_generator.cpython-313.pyc +0 -0
  152. package/tools/__pycache__/base64_tools.cpython-313.pyc +0 -0
  153. package/tools/__pycache__/base_tool.cpython-313.pyc +0 -0
  154. package/tools/__pycache__/case_tool.cpython-313.pyc +0 -0
  155. package/tools/__pycache__/column_tools.cpython-313.pyc +0 -0
  156. package/tools/__pycache__/cron_tool.cpython-313.pyc +0 -0
  157. package/tools/__pycache__/curl_history.cpython-313.pyc +0 -0
  158. package/tools/__pycache__/curl_processor.cpython-313.pyc +0 -0
  159. package/tools/__pycache__/curl_settings.cpython-313.pyc +0 -0
  160. package/tools/__pycache__/curl_tool.cpython-313.pyc +0 -0
  161. package/tools/__pycache__/diff_viewer.cpython-313.pyc +0 -0
  162. package/tools/__pycache__/email_extraction_tool.cpython-313.pyc +0 -0
  163. package/tools/__pycache__/email_header_analyzer.cpython-313.pyc +0 -0
  164. package/tools/__pycache__/extraction_tools.cpython-313.pyc +0 -0
  165. package/tools/__pycache__/find_replace.cpython-313.pyc +0 -0
  166. package/tools/__pycache__/folder_file_reporter.cpython-313.pyc +0 -0
  167. package/tools/__pycache__/folder_file_reporter_adapter.cpython-313.pyc +0 -0
  168. package/tools/__pycache__/generator_tools.cpython-313.pyc +0 -0
  169. package/tools/__pycache__/hash_generator.cpython-313.pyc +0 -0
  170. package/tools/__pycache__/html_tool.cpython-313.pyc +0 -0
  171. package/tools/__pycache__/huggingface_helper.cpython-313.pyc +0 -0
  172. package/tools/__pycache__/jsonxml_tool.cpython-313.pyc +0 -0
  173. package/tools/__pycache__/line_tools.cpython-313.pyc +0 -0
  174. package/tools/__pycache__/list_comparator.cpython-313.pyc +0 -0
  175. package/tools/__pycache__/markdown_tools.cpython-313.pyc +0 -0
  176. package/tools/__pycache__/mcp_widget.cpython-313.pyc +0 -0
  177. package/tools/__pycache__/notes_widget.cpython-313.pyc +0 -0
  178. package/tools/__pycache__/number_base_converter.cpython-313.pyc +0 -0
  179. package/tools/__pycache__/regex_extractor.cpython-313.pyc +0 -0
  180. package/tools/__pycache__/slug_generator.cpython-313.pyc +0 -0
  181. package/tools/__pycache__/sorter_tools.cpython-313.pyc +0 -0
  182. package/tools/__pycache__/string_escape_tool.cpython-313.pyc +0 -0
  183. package/tools/__pycache__/text_statistics_tool.cpython-313.pyc +0 -0
  184. package/tools/__pycache__/text_wrapper.cpython-313.pyc +0 -0
  185. package/tools/__pycache__/timestamp_converter.cpython-313.pyc +0 -0
  186. package/tools/__pycache__/tool_loader.cpython-313.pyc +0 -0
  187. package/tools/__pycache__/translator_tools.cpython-313.pyc +0 -0
  188. package/tools/__pycache__/url_link_extractor.cpython-313.pyc +0 -0
  189. package/tools/__pycache__/url_parser.cpython-313.pyc +0 -0
  190. package/tools/__pycache__/whitespace_tools.cpython-313.pyc +0 -0
  191. package/tools/__pycache__/word_frequency_counter.cpython-313.pyc +0 -0
@@ -1,431 +1,431 @@
1
- """
2
- Text Wrapper/Formatter Module - Text formatting utilities
3
-
4
- This module provides text wrapping and formatting functionality
5
- for the Pomera AI Commander application.
6
-
7
- Features:
8
- - Word Wrap: Wrap text at specified column width
9
- - Justify Text: Left, right, center, full justify
10
- - Add Prefix/Suffix: Add text to start/end of each line
11
- - Indent/Dedent: Add or remove indentation
12
- """
13
-
14
- import tkinter as tk
15
- from tkinter import ttk
16
- import textwrap
17
-
18
-
19
- class TextWrapperProcessor:
20
- """Text wrapper processor with various formatting capabilities."""
21
-
22
- @staticmethod
23
- def word_wrap(text, width=80, break_long_words=True, break_on_hyphens=True):
24
- """Wrap text at specified column width."""
25
- lines = text.split('\n')
26
- wrapped_lines = []
27
-
28
- for line in lines:
29
- if line.strip():
30
- wrapped = textwrap.fill(
31
- line,
32
- width=width,
33
- break_long_words=break_long_words,
34
- break_on_hyphens=break_on_hyphens
35
- )
36
- wrapped_lines.append(wrapped)
37
- else:
38
- wrapped_lines.append('')
39
-
40
- return '\n'.join(wrapped_lines)
41
-
42
- @staticmethod
43
- def justify_text(text, width=80, mode="left"):
44
- """Justify text to specified width."""
45
- lines = text.split('\n')
46
- result = []
47
-
48
- for line in lines:
49
- line = line.strip()
50
- if not line:
51
- result.append('')
52
- continue
53
-
54
- if mode == "left":
55
- result.append(line.ljust(width))
56
- elif mode == "right":
57
- result.append(line.rjust(width))
58
- elif mode == "center":
59
- result.append(line.center(width))
60
- elif mode == "full":
61
- # Full justify - distribute spaces evenly
62
- words = line.split()
63
- if len(words) == 1:
64
- result.append(line.ljust(width))
65
- else:
66
- total_spaces = width - sum(len(w) for w in words)
67
- gaps = len(words) - 1
68
- if gaps > 0:
69
- space_per_gap = total_spaces // gaps
70
- extra_spaces = total_spaces % gaps
71
- justified = words[0]
72
- for i, word in enumerate(words[1:]):
73
- spaces = space_per_gap + (1 if i < extra_spaces else 0)
74
- justified += ' ' * spaces + word
75
- result.append(justified)
76
- else:
77
- result.append(line)
78
- else:
79
- result.append(line)
80
-
81
- return '\n'.join(result)
82
-
83
- @staticmethod
84
- def add_prefix_suffix(text, prefix="", suffix="", skip_empty=True):
85
- """Add prefix and/or suffix to each line."""
86
- lines = text.split('\n')
87
- result = []
88
-
89
- for line in lines:
90
- if skip_empty and not line.strip():
91
- result.append(line)
92
- else:
93
- result.append(f"{prefix}{line}{suffix}")
94
-
95
- return '\n'.join(result)
96
-
97
- @staticmethod
98
- def indent(text, size=4, char="space"):
99
- """Add indentation to each line."""
100
- indent_char = '\t' if char == "tab" else ' '
101
- indent_str = indent_char * size if char == "space" else indent_char * size
102
-
103
- lines = text.split('\n')
104
- result = [indent_str + line if line.strip() else line for line in lines]
105
-
106
- return '\n'.join(result)
107
-
108
- @staticmethod
109
- def dedent(text, size=4):
110
- """Remove indentation from each line."""
111
- lines = text.split('\n')
112
- result = []
113
-
114
- for line in lines:
115
- # Count leading whitespace
116
- stripped = line.lstrip()
117
- leading = len(line) - len(stripped)
118
-
119
- # Remove up to 'size' characters of indentation
120
- remove = min(leading, size)
121
- result.append(line[remove:])
122
-
123
- return '\n'.join(result)
124
-
125
- @staticmethod
126
- def quote_text(text, style="double"):
127
- """Wrap text in quotes or code blocks."""
128
- if style == "double":
129
- return f'"{text}"'
130
- elif style == "single":
131
- return f"'{text}'"
132
- elif style == "backtick":
133
- return f"`{text}`"
134
- elif style == "code_block":
135
- return f"```\n{text}\n```"
136
- elif style == "blockquote":
137
- lines = text.split('\n')
138
- return '\n'.join(f"> {line}" for line in lines)
139
- else:
140
- return text
141
-
142
-
143
- class TextWrapperWidget(ttk.Frame):
144
- """Tabbed interface widget for text wrapper tools."""
145
-
146
- def __init__(self, parent, app):
147
- super().__init__(parent)
148
- self.app = app
149
- self.processor = TextWrapperProcessor()
150
-
151
- self.wrap_width = tk.IntVar(value=80)
152
- self.justify_mode = tk.StringVar(value="left")
153
- self.justify_width = tk.IntVar(value=80)
154
- self.prefix = tk.StringVar(value="")
155
- self.suffix = tk.StringVar(value="")
156
- self.skip_empty = tk.BooleanVar(value=True)
157
- self.indent_size = tk.IntVar(value=4)
158
- self.indent_char = tk.StringVar(value="space")
159
- self.quote_style = tk.StringVar(value="double")
160
-
161
- self.create_widgets()
162
- self.load_settings()
163
-
164
- def create_widgets(self):
165
- """Creates the tabbed interface for text wrapper tools."""
166
- self.notebook = ttk.Notebook(self)
167
- self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
168
-
169
- self.create_wrap_tab()
170
- self.create_justify_tab()
171
- self.create_prefix_suffix_tab()
172
- self.create_indent_tab()
173
- self.create_quote_tab()
174
-
175
- def create_wrap_tab(self):
176
- """Creates the Word Wrap tab."""
177
- frame = ttk.Frame(self.notebook)
178
- self.notebook.add(frame, text="Word Wrap")
179
-
180
- width_frame = ttk.Frame(frame)
181
- width_frame.pack(fill=tk.X, padx=5, pady=10)
182
-
183
- ttk.Label(width_frame, text="Line Width:").pack(side=tk.LEFT)
184
- ttk.Spinbox(width_frame, from_=20, to=200, width=5,
185
- textvariable=self.wrap_width,
186
- command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
187
- ttk.Label(width_frame, text="characters").pack(side=tk.LEFT)
188
-
189
- ttk.Button(frame, text="Wrap Text",
190
- command=lambda: self.process("wrap")).pack(pady=10)
191
-
192
- def create_justify_tab(self):
193
- """Creates the Justify Text tab."""
194
- frame = ttk.Frame(self.notebook)
195
- self.notebook.add(frame, text="Justify")
196
-
197
- mode_frame = ttk.LabelFrame(frame, text="Alignment", padding=10)
198
- mode_frame.pack(fill=tk.X, padx=5, pady=5)
199
-
200
- modes = [("Left", "left"), ("Right", "right"),
201
- ("Center", "center"), ("Full", "full")]
202
- for text, value in modes:
203
- ttk.Radiobutton(mode_frame, text=text,
204
- variable=self.justify_mode, value=value,
205
- command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
206
-
207
- width_frame = ttk.Frame(frame)
208
- width_frame.pack(fill=tk.X, padx=5, pady=5)
209
-
210
- ttk.Label(width_frame, text="Width:").pack(side=tk.LEFT)
211
- ttk.Spinbox(width_frame, from_=20, to=200, width=5,
212
- textvariable=self.justify_width,
213
- command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
214
-
215
- ttk.Button(frame, text="Justify Text",
216
- command=lambda: self.process("justify")).pack(pady=10)
217
-
218
- def create_prefix_suffix_tab(self):
219
- """Creates the Prefix/Suffix tab."""
220
- frame = ttk.Frame(self.notebook)
221
- self.notebook.add(frame, text="Prefix/Suffix")
222
-
223
- prefix_frame = ttk.Frame(frame)
224
- prefix_frame.pack(fill=tk.X, padx=5, pady=5)
225
- ttk.Label(prefix_frame, text="Prefix:").pack(side=tk.LEFT)
226
- ttk.Entry(prefix_frame, textvariable=self.prefix, width=20).pack(side=tk.LEFT, padx=5)
227
-
228
- suffix_frame = ttk.Frame(frame)
229
- suffix_frame.pack(fill=tk.X, padx=5, pady=5)
230
- ttk.Label(suffix_frame, text="Suffix:").pack(side=tk.LEFT)
231
- ttk.Entry(suffix_frame, textvariable=self.suffix, width=20).pack(side=tk.LEFT, padx=5)
232
-
233
- ttk.Checkbutton(frame, text="Skip Empty Lines",
234
- variable=self.skip_empty,
235
- command=self.on_setting_change).pack(anchor=tk.W, padx=5, pady=5)
236
-
237
- ttk.Button(frame, text="Add Prefix/Suffix",
238
- command=lambda: self.process("prefix_suffix")).pack(pady=10)
239
-
240
- def create_indent_tab(self):
241
- """Creates the Indent/Dedent tab."""
242
- frame = ttk.Frame(self.notebook)
243
- self.notebook.add(frame, text="Indent")
244
-
245
- size_frame = ttk.Frame(frame)
246
- size_frame.pack(fill=tk.X, padx=5, pady=5)
247
- ttk.Label(size_frame, text="Indent Size:").pack(side=tk.LEFT)
248
- ttk.Spinbox(size_frame, from_=1, to=16, width=4,
249
- textvariable=self.indent_size,
250
- command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
251
-
252
- char_frame = ttk.LabelFrame(frame, text="Indent Character", padding=10)
253
- char_frame.pack(fill=tk.X, padx=5, pady=5)
254
-
255
- ttk.Radiobutton(char_frame, text="Spaces",
256
- variable=self.indent_char, value="space",
257
- command=self.on_setting_change).pack(side=tk.LEFT, padx=10)
258
- ttk.Radiobutton(char_frame, text="Tabs",
259
- variable=self.indent_char, value="tab",
260
- command=self.on_setting_change).pack(side=tk.LEFT, padx=10)
261
-
262
- buttons_frame = ttk.Frame(frame)
263
- buttons_frame.pack(pady=10)
264
-
265
- ttk.Button(buttons_frame, text="Indent",
266
- command=lambda: self.process("indent")).pack(side=tk.LEFT, padx=5)
267
- ttk.Button(buttons_frame, text="Dedent",
268
- command=lambda: self.process("dedent")).pack(side=tk.LEFT, padx=5)
269
-
270
- def create_quote_tab(self):
271
- """Creates the Quote Text tab."""
272
- frame = ttk.Frame(self.notebook)
273
- self.notebook.add(frame, text="Quote")
274
-
275
- style_frame = ttk.LabelFrame(frame, text="Quote Style", padding=10)
276
- style_frame.pack(fill=tk.X, padx=5, pady=5)
277
-
278
- styles = [
279
- ('Double Quotes ("...")', "double"),
280
- ("Single Quotes ('...')", "single"),
281
- ("Backticks (`...`)", "backtick"),
282
- ("Code Block (```...```)", "code_block"),
283
- ("Blockquote (> ...)", "blockquote"),
284
- ]
285
-
286
- for text, value in styles:
287
- ttk.Radiobutton(style_frame, text=text,
288
- variable=self.quote_style, value=value,
289
- command=self.on_setting_change).pack(anchor=tk.W)
290
-
291
- ttk.Button(frame, text="Quote Text",
292
- command=lambda: self.process("quote")).pack(pady=10)
293
-
294
- def load_settings(self):
295
- """Load settings from the application."""
296
- settings = self.app.settings.get("tool_settings", {}).get("Text Wrapper", {})
297
-
298
- self.wrap_width.set(settings.get("wrap_width", 80))
299
- self.justify_mode.set(settings.get("justify_mode", "left"))
300
- self.justify_width.set(settings.get("justify_width", 80))
301
- self.prefix.set(settings.get("prefix", ""))
302
- self.suffix.set(settings.get("suffix", ""))
303
- self.skip_empty.set(settings.get("skip_empty", True))
304
- self.indent_size.set(settings.get("indent_size", 4))
305
- self.indent_char.set(settings.get("indent_char", "space"))
306
- self.quote_style.set(settings.get("quote_style", "double"))
307
-
308
- def save_settings(self):
309
- """Save current settings to the application."""
310
- if "Text Wrapper" not in self.app.settings["tool_settings"]:
311
- self.app.settings["tool_settings"]["Text Wrapper"] = {}
312
-
313
- self.app.settings["tool_settings"]["Text Wrapper"].update({
314
- "wrap_width": self.wrap_width.get(),
315
- "justify_mode": self.justify_mode.get(),
316
- "justify_width": self.justify_width.get(),
317
- "prefix": self.prefix.get(),
318
- "suffix": self.suffix.get(),
319
- "skip_empty": self.skip_empty.get(),
320
- "indent_size": self.indent_size.get(),
321
- "indent_char": self.indent_char.get(),
322
- "quote_style": self.quote_style.get()
323
- })
324
-
325
- self.app.save_settings()
326
-
327
- def on_setting_change(self, *args):
328
- """Handle setting changes."""
329
- self.save_settings()
330
-
331
- def process(self, operation):
332
- """Process the input text."""
333
- active_input_tab = self.app.input_tabs[self.app.input_notebook.index(self.app.input_notebook.select())]
334
- input_text = active_input_tab.text.get("1.0", tk.END).rstrip('\n')
335
-
336
- if not input_text:
337
- return
338
-
339
- if operation == "wrap":
340
- result = TextWrapperProcessor.word_wrap(input_text, self.wrap_width.get())
341
- elif operation == "justify":
342
- result = TextWrapperProcessor.justify_text(
343
- input_text, self.justify_width.get(), self.justify_mode.get())
344
- elif operation == "prefix_suffix":
345
- result = TextWrapperProcessor.add_prefix_suffix(
346
- input_text, self.prefix.get(), self.suffix.get(), self.skip_empty.get())
347
- elif operation == "indent":
348
- result = TextWrapperProcessor.indent(
349
- input_text, self.indent_size.get(), self.indent_char.get())
350
- elif operation == "dedent":
351
- result = TextWrapperProcessor.dedent(input_text, self.indent_size.get())
352
- elif operation == "quote":
353
- result = TextWrapperProcessor.quote_text(input_text, self.quote_style.get())
354
- else:
355
- result = input_text
356
-
357
- active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
358
- active_output_tab.text.config(state="normal")
359
- active_output_tab.text.delete("1.0", tk.END)
360
- active_output_tab.text.insert("1.0", result)
361
- active_output_tab.text.config(state="disabled")
362
-
363
- self.app.update_all_stats()
364
-
365
-
366
- class TextWrapper:
367
- """Main class for Text Wrapper integration."""
368
-
369
- def __init__(self):
370
- self.processor = TextWrapperProcessor()
371
-
372
- def create_widget(self, parent, app):
373
- """Create and return the Text Wrapper widget."""
374
- return TextWrapperWidget(parent, app)
375
-
376
- def get_default_settings(self):
377
- """Return default settings for Text Wrapper."""
378
- return {
379
- "wrap_width": 80,
380
- "justify_mode": "left",
381
- "justify_width": 80,
382
- "prefix": "",
383
- "suffix": "",
384
- "skip_empty": True,
385
- "indent_size": 4,
386
- "indent_char": "space",
387
- "quote_style": "double"
388
- }
389
-
390
-
391
- # BaseTool-compatible wrapper
392
- try:
393
- from tools.base_tool import BaseTool
394
- from typing import Dict, Any, Optional, Callable
395
-
396
- class TextWrapperV2(BaseTool):
397
- """
398
- BaseTool-compatible version of TextWrapper.
399
- """
400
-
401
- TOOL_NAME = "Text Wrapper"
402
- TOOL_DESCRIPTION = "Wrap text to specified width"
403
- TOOL_VERSION = "2.0.0"
404
-
405
- def __init__(self):
406
- super().__init__()
407
- self._processor = TextWrapperProcessor()
408
-
409
- def process_text(self, input_text: str, settings: Dict[str, Any]) -> str:
410
- """Wrap text to specified width."""
411
- width = settings.get("width", 80)
412
- return TextWrapperProcessor.word_wrap(input_text, width)
413
-
414
- def create_ui(self,
415
- parent,
416
- settings: Dict[str, Any],
417
- on_setting_change_callback: Optional[Callable] = None,
418
- apply_tool_callback: Optional[Callable] = None):
419
- """Create minimal UI - full widget used separately."""
420
- self._settings = settings.copy()
421
- self._on_setting_change = on_setting_change_callback
422
- self._apply_callback = apply_tool_callback
423
- return None
424
-
425
- @classmethod
426
- def get_default_settings(cls) -> Dict[str, Any]:
427
- """Return default settings."""
428
- return {"width": 80}
429
-
430
- except ImportError:
1
+ """
2
+ Text Wrapper/Formatter Module - Text formatting utilities
3
+
4
+ This module provides text wrapping and formatting functionality
5
+ for the Pomera AI Commander application.
6
+
7
+ Features:
8
+ - Word Wrap: Wrap text at specified column width
9
+ - Justify Text: Left, right, center, full justify
10
+ - Add Prefix/Suffix: Add text to start/end of each line
11
+ - Indent/Dedent: Add or remove indentation
12
+ """
13
+
14
+ import tkinter as tk
15
+ from tkinter import ttk
16
+ import textwrap
17
+
18
+
19
+ class TextWrapperProcessor:
20
+ """Text wrapper processor with various formatting capabilities."""
21
+
22
+ @staticmethod
23
+ def word_wrap(text, width=80, break_long_words=True, break_on_hyphens=True):
24
+ """Wrap text at specified column width."""
25
+ lines = text.split('\n')
26
+ wrapped_lines = []
27
+
28
+ for line in lines:
29
+ if line.strip():
30
+ wrapped = textwrap.fill(
31
+ line,
32
+ width=width,
33
+ break_long_words=break_long_words,
34
+ break_on_hyphens=break_on_hyphens
35
+ )
36
+ wrapped_lines.append(wrapped)
37
+ else:
38
+ wrapped_lines.append('')
39
+
40
+ return '\n'.join(wrapped_lines)
41
+
42
+ @staticmethod
43
+ def justify_text(text, width=80, mode="left"):
44
+ """Justify text to specified width."""
45
+ lines = text.split('\n')
46
+ result = []
47
+
48
+ for line in lines:
49
+ line = line.strip()
50
+ if not line:
51
+ result.append('')
52
+ continue
53
+
54
+ if mode == "left":
55
+ result.append(line.ljust(width))
56
+ elif mode == "right":
57
+ result.append(line.rjust(width))
58
+ elif mode == "center":
59
+ result.append(line.center(width))
60
+ elif mode == "full":
61
+ # Full justify - distribute spaces evenly
62
+ words = line.split()
63
+ if len(words) == 1:
64
+ result.append(line.ljust(width))
65
+ else:
66
+ total_spaces = width - sum(len(w) for w in words)
67
+ gaps = len(words) - 1
68
+ if gaps > 0:
69
+ space_per_gap = total_spaces // gaps
70
+ extra_spaces = total_spaces % gaps
71
+ justified = words[0]
72
+ for i, word in enumerate(words[1:]):
73
+ spaces = space_per_gap + (1 if i < extra_spaces else 0)
74
+ justified += ' ' * spaces + word
75
+ result.append(justified)
76
+ else:
77
+ result.append(line)
78
+ else:
79
+ result.append(line)
80
+
81
+ return '\n'.join(result)
82
+
83
+ @staticmethod
84
+ def add_prefix_suffix(text, prefix="", suffix="", skip_empty=True):
85
+ """Add prefix and/or suffix to each line."""
86
+ lines = text.split('\n')
87
+ result = []
88
+
89
+ for line in lines:
90
+ if skip_empty and not line.strip():
91
+ result.append(line)
92
+ else:
93
+ result.append(f"{prefix}{line}{suffix}")
94
+
95
+ return '\n'.join(result)
96
+
97
+ @staticmethod
98
+ def indent(text, size=4, char="space"):
99
+ """Add indentation to each line."""
100
+ indent_char = '\t' if char == "tab" else ' '
101
+ indent_str = indent_char * size if char == "space" else indent_char * size
102
+
103
+ lines = text.split('\n')
104
+ result = [indent_str + line if line.strip() else line for line in lines]
105
+
106
+ return '\n'.join(result)
107
+
108
+ @staticmethod
109
+ def dedent(text, size=4):
110
+ """Remove indentation from each line."""
111
+ lines = text.split('\n')
112
+ result = []
113
+
114
+ for line in lines:
115
+ # Count leading whitespace
116
+ stripped = line.lstrip()
117
+ leading = len(line) - len(stripped)
118
+
119
+ # Remove up to 'size' characters of indentation
120
+ remove = min(leading, size)
121
+ result.append(line[remove:])
122
+
123
+ return '\n'.join(result)
124
+
125
+ @staticmethod
126
+ def quote_text(text, style="double"):
127
+ """Wrap text in quotes or code blocks."""
128
+ if style == "double":
129
+ return f'"{text}"'
130
+ elif style == "single":
131
+ return f"'{text}'"
132
+ elif style == "backtick":
133
+ return f"`{text}`"
134
+ elif style == "code_block":
135
+ return f"```\n{text}\n```"
136
+ elif style == "blockquote":
137
+ lines = text.split('\n')
138
+ return '\n'.join(f"> {line}" for line in lines)
139
+ else:
140
+ return text
141
+
142
+
143
+ class TextWrapperWidget(ttk.Frame):
144
+ """Tabbed interface widget for text wrapper tools."""
145
+
146
+ def __init__(self, parent, app):
147
+ super().__init__(parent)
148
+ self.app = app
149
+ self.processor = TextWrapperProcessor()
150
+
151
+ self.wrap_width = tk.IntVar(value=80)
152
+ self.justify_mode = tk.StringVar(value="left")
153
+ self.justify_width = tk.IntVar(value=80)
154
+ self.prefix = tk.StringVar(value="")
155
+ self.suffix = tk.StringVar(value="")
156
+ self.skip_empty = tk.BooleanVar(value=True)
157
+ self.indent_size = tk.IntVar(value=4)
158
+ self.indent_char = tk.StringVar(value="space")
159
+ self.quote_style = tk.StringVar(value="double")
160
+
161
+ self.create_widgets()
162
+ self.load_settings()
163
+
164
+ def create_widgets(self):
165
+ """Creates the tabbed interface for text wrapper tools."""
166
+ self.notebook = ttk.Notebook(self)
167
+ self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
168
+
169
+ self.create_wrap_tab()
170
+ self.create_justify_tab()
171
+ self.create_prefix_suffix_tab()
172
+ self.create_indent_tab()
173
+ self.create_quote_tab()
174
+
175
+ def create_wrap_tab(self):
176
+ """Creates the Word Wrap tab."""
177
+ frame = ttk.Frame(self.notebook)
178
+ self.notebook.add(frame, text="Word Wrap")
179
+
180
+ width_frame = ttk.Frame(frame)
181
+ width_frame.pack(fill=tk.X, padx=5, pady=10)
182
+
183
+ ttk.Label(width_frame, text="Line Width:").pack(side=tk.LEFT)
184
+ ttk.Spinbox(width_frame, from_=20, to=200, width=5,
185
+ textvariable=self.wrap_width,
186
+ command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
187
+ ttk.Label(width_frame, text="characters").pack(side=tk.LEFT)
188
+
189
+ ttk.Button(frame, text="Wrap Text",
190
+ command=lambda: self.process("wrap")).pack(pady=10)
191
+
192
+ def create_justify_tab(self):
193
+ """Creates the Justify Text tab."""
194
+ frame = ttk.Frame(self.notebook)
195
+ self.notebook.add(frame, text="Justify")
196
+
197
+ mode_frame = ttk.LabelFrame(frame, text="Alignment", padding=10)
198
+ mode_frame.pack(fill=tk.X, padx=5, pady=5)
199
+
200
+ modes = [("Left", "left"), ("Right", "right"),
201
+ ("Center", "center"), ("Full", "full")]
202
+ for text, value in modes:
203
+ ttk.Radiobutton(mode_frame, text=text,
204
+ variable=self.justify_mode, value=value,
205
+ command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
206
+
207
+ width_frame = ttk.Frame(frame)
208
+ width_frame.pack(fill=tk.X, padx=5, pady=5)
209
+
210
+ ttk.Label(width_frame, text="Width:").pack(side=tk.LEFT)
211
+ ttk.Spinbox(width_frame, from_=20, to=200, width=5,
212
+ textvariable=self.justify_width,
213
+ command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
214
+
215
+ ttk.Button(frame, text="Justify Text",
216
+ command=lambda: self.process("justify")).pack(pady=10)
217
+
218
+ def create_prefix_suffix_tab(self):
219
+ """Creates the Prefix/Suffix tab."""
220
+ frame = ttk.Frame(self.notebook)
221
+ self.notebook.add(frame, text="Prefix/Suffix")
222
+
223
+ prefix_frame = ttk.Frame(frame)
224
+ prefix_frame.pack(fill=tk.X, padx=5, pady=5)
225
+ ttk.Label(prefix_frame, text="Prefix:").pack(side=tk.LEFT)
226
+ ttk.Entry(prefix_frame, textvariable=self.prefix, width=20).pack(side=tk.LEFT, padx=5)
227
+
228
+ suffix_frame = ttk.Frame(frame)
229
+ suffix_frame.pack(fill=tk.X, padx=5, pady=5)
230
+ ttk.Label(suffix_frame, text="Suffix:").pack(side=tk.LEFT)
231
+ ttk.Entry(suffix_frame, textvariable=self.suffix, width=20).pack(side=tk.LEFT, padx=5)
232
+
233
+ ttk.Checkbutton(frame, text="Skip Empty Lines",
234
+ variable=self.skip_empty,
235
+ command=self.on_setting_change).pack(anchor=tk.W, padx=5, pady=5)
236
+
237
+ ttk.Button(frame, text="Add Prefix/Suffix",
238
+ command=lambda: self.process("prefix_suffix")).pack(pady=10)
239
+
240
+ def create_indent_tab(self):
241
+ """Creates the Indent/Dedent tab."""
242
+ frame = ttk.Frame(self.notebook)
243
+ self.notebook.add(frame, text="Indent")
244
+
245
+ size_frame = ttk.Frame(frame)
246
+ size_frame.pack(fill=tk.X, padx=5, pady=5)
247
+ ttk.Label(size_frame, text="Indent Size:").pack(side=tk.LEFT)
248
+ ttk.Spinbox(size_frame, from_=1, to=16, width=4,
249
+ textvariable=self.indent_size,
250
+ command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
251
+
252
+ char_frame = ttk.LabelFrame(frame, text="Indent Character", padding=10)
253
+ char_frame.pack(fill=tk.X, padx=5, pady=5)
254
+
255
+ ttk.Radiobutton(char_frame, text="Spaces",
256
+ variable=self.indent_char, value="space",
257
+ command=self.on_setting_change).pack(side=tk.LEFT, padx=10)
258
+ ttk.Radiobutton(char_frame, text="Tabs",
259
+ variable=self.indent_char, value="tab",
260
+ command=self.on_setting_change).pack(side=tk.LEFT, padx=10)
261
+
262
+ buttons_frame = ttk.Frame(frame)
263
+ buttons_frame.pack(pady=10)
264
+
265
+ ttk.Button(buttons_frame, text="Indent",
266
+ command=lambda: self.process("indent")).pack(side=tk.LEFT, padx=5)
267
+ ttk.Button(buttons_frame, text="Dedent",
268
+ command=lambda: self.process("dedent")).pack(side=tk.LEFT, padx=5)
269
+
270
+ def create_quote_tab(self):
271
+ """Creates the Quote Text tab."""
272
+ frame = ttk.Frame(self.notebook)
273
+ self.notebook.add(frame, text="Quote")
274
+
275
+ style_frame = ttk.LabelFrame(frame, text="Quote Style", padding=10)
276
+ style_frame.pack(fill=tk.X, padx=5, pady=5)
277
+
278
+ styles = [
279
+ ('Double Quotes ("...")', "double"),
280
+ ("Single Quotes ('...')", "single"),
281
+ ("Backticks (`...`)", "backtick"),
282
+ ("Code Block (```...```)", "code_block"),
283
+ ("Blockquote (> ...)", "blockquote"),
284
+ ]
285
+
286
+ for text, value in styles:
287
+ ttk.Radiobutton(style_frame, text=text,
288
+ variable=self.quote_style, value=value,
289
+ command=self.on_setting_change).pack(anchor=tk.W)
290
+
291
+ ttk.Button(frame, text="Quote Text",
292
+ command=lambda: self.process("quote")).pack(pady=10)
293
+
294
+ def load_settings(self):
295
+ """Load settings from the application."""
296
+ settings = self.app.settings.get("tool_settings", {}).get("Text Wrapper", {})
297
+
298
+ self.wrap_width.set(settings.get("wrap_width", 80))
299
+ self.justify_mode.set(settings.get("justify_mode", "left"))
300
+ self.justify_width.set(settings.get("justify_width", 80))
301
+ self.prefix.set(settings.get("prefix", ""))
302
+ self.suffix.set(settings.get("suffix", ""))
303
+ self.skip_empty.set(settings.get("skip_empty", True))
304
+ self.indent_size.set(settings.get("indent_size", 4))
305
+ self.indent_char.set(settings.get("indent_char", "space"))
306
+ self.quote_style.set(settings.get("quote_style", "double"))
307
+
308
+ def save_settings(self):
309
+ """Save current settings to the application."""
310
+ if "Text Wrapper" not in self.app.settings["tool_settings"]:
311
+ self.app.settings["tool_settings"]["Text Wrapper"] = {}
312
+
313
+ self.app.settings["tool_settings"]["Text Wrapper"].update({
314
+ "wrap_width": self.wrap_width.get(),
315
+ "justify_mode": self.justify_mode.get(),
316
+ "justify_width": self.justify_width.get(),
317
+ "prefix": self.prefix.get(),
318
+ "suffix": self.suffix.get(),
319
+ "skip_empty": self.skip_empty.get(),
320
+ "indent_size": self.indent_size.get(),
321
+ "indent_char": self.indent_char.get(),
322
+ "quote_style": self.quote_style.get()
323
+ })
324
+
325
+ self.app.save_settings()
326
+
327
+ def on_setting_change(self, *args):
328
+ """Handle setting changes."""
329
+ self.save_settings()
330
+
331
+ def process(self, operation):
332
+ """Process the input text."""
333
+ active_input_tab = self.app.input_tabs[self.app.input_notebook.index(self.app.input_notebook.select())]
334
+ input_text = active_input_tab.text.get("1.0", tk.END).rstrip('\n')
335
+
336
+ if not input_text:
337
+ return
338
+
339
+ if operation == "wrap":
340
+ result = TextWrapperProcessor.word_wrap(input_text, self.wrap_width.get())
341
+ elif operation == "justify":
342
+ result = TextWrapperProcessor.justify_text(
343
+ input_text, self.justify_width.get(), self.justify_mode.get())
344
+ elif operation == "prefix_suffix":
345
+ result = TextWrapperProcessor.add_prefix_suffix(
346
+ input_text, self.prefix.get(), self.suffix.get(), self.skip_empty.get())
347
+ elif operation == "indent":
348
+ result = TextWrapperProcessor.indent(
349
+ input_text, self.indent_size.get(), self.indent_char.get())
350
+ elif operation == "dedent":
351
+ result = TextWrapperProcessor.dedent(input_text, self.indent_size.get())
352
+ elif operation == "quote":
353
+ result = TextWrapperProcessor.quote_text(input_text, self.quote_style.get())
354
+ else:
355
+ result = input_text
356
+
357
+ active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
358
+ active_output_tab.text.config(state="normal")
359
+ active_output_tab.text.delete("1.0", tk.END)
360
+ active_output_tab.text.insert("1.0", result)
361
+ active_output_tab.text.config(state="disabled")
362
+
363
+ self.app.update_all_stats()
364
+
365
+
366
+ class TextWrapper:
367
+ """Main class for Text Wrapper integration."""
368
+
369
+ def __init__(self):
370
+ self.processor = TextWrapperProcessor()
371
+
372
+ def create_widget(self, parent, app):
373
+ """Create and return the Text Wrapper widget."""
374
+ return TextWrapperWidget(parent, app)
375
+
376
+ def get_default_settings(self):
377
+ """Return default settings for Text Wrapper."""
378
+ return {
379
+ "wrap_width": 80,
380
+ "justify_mode": "left",
381
+ "justify_width": 80,
382
+ "prefix": "",
383
+ "suffix": "",
384
+ "skip_empty": True,
385
+ "indent_size": 4,
386
+ "indent_char": "space",
387
+ "quote_style": "double"
388
+ }
389
+
390
+
391
+ # BaseTool-compatible wrapper
392
+ try:
393
+ from tools.base_tool import BaseTool
394
+ from typing import Dict, Any, Optional, Callable
395
+
396
+ class TextWrapperV2(BaseTool):
397
+ """
398
+ BaseTool-compatible version of TextWrapper.
399
+ """
400
+
401
+ TOOL_NAME = "Text Wrapper"
402
+ TOOL_DESCRIPTION = "Wrap text to specified width"
403
+ TOOL_VERSION = "2.0.0"
404
+
405
+ def __init__(self):
406
+ super().__init__()
407
+ self._processor = TextWrapperProcessor()
408
+
409
+ def process_text(self, input_text: str, settings: Dict[str, Any]) -> str:
410
+ """Wrap text to specified width."""
411
+ width = settings.get("width", 80)
412
+ return TextWrapperProcessor.word_wrap(input_text, width)
413
+
414
+ def create_ui(self,
415
+ parent,
416
+ settings: Dict[str, Any],
417
+ on_setting_change_callback: Optional[Callable] = None,
418
+ apply_tool_callback: Optional[Callable] = None):
419
+ """Create minimal UI - full widget used separately."""
420
+ self._settings = settings.copy()
421
+ self._on_setting_change = on_setting_change_callback
422
+ self._apply_callback = apply_tool_callback
423
+ return None
424
+
425
+ @classmethod
426
+ def get_default_settings(cls) -> Dict[str, Any]:
427
+ """Return default settings."""
428
+ return {"width": 80}
429
+
430
+ except ImportError:
431
431
  pass