omniline 0.1__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.
omniline/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """OmniLine frontends and their shared user-facing models."""
omniline/__main__.py ADDED
@@ -0,0 +1,78 @@
1
+ """OmniLine frontend dispatch and session lifecycle."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import os
7
+ import sys
8
+ from collections.abc import Sequence
9
+ from pathlib import Path
10
+
11
+ from okline import OkLine
12
+ from okline._util import reconfigure_stdout_utf8
13
+
14
+ from .cli import run_history, run_list
15
+ from .tui import run_tui
16
+
17
+
18
+ def _build_parser() -> argparse.ArgumentParser:
19
+ parser = argparse.ArgumentParser(prog="omniline")
20
+ frontends = parser.add_subparsers(dest="frontend", required=True)
21
+ tui = frontends.add_parser("tui", help="read-only terminal UI")
22
+ tui.add_argument("--tokens-file", default=None, help="session JSON file")
23
+ cli = frontends.add_parser("cli", help="command-line frontend")
24
+ commands = cli.add_subparsers(dest="command", required=True)
25
+
26
+ listing = commands.add_parser("list", help="list friends and groups")
27
+ listing.add_argument("-s", "--sort", choices=("lmtime", "name"), default="name")
28
+ listing.add_argument("--json", action="store_true", help="full JSON output")
29
+ listing.add_argument("--csv", action="store_true", help="short CSV output")
30
+ listing.add_argument("-f", "--full", action="store_true", help="full JSON output")
31
+ listing.add_argument("--tokens-file", default=None, help="session JSON file")
32
+
33
+ history = commands.add_parser("hist", help="dump recent history for one chat")
34
+ history.add_argument("-n", type=int, default=50, help="maximum number of messages")
35
+ history.add_argument("needle", help="substring of a chat MID or display name")
36
+ history.add_argument("--tokens-file", default=None, help="session JSON file")
37
+ return parser
38
+
39
+
40
+ def _token_path(explicit: str | None) -> Path:
41
+ if explicit:
42
+ return Path(explicit)
43
+ for candidate in (Path("tokens.json"), Path("worksp/tokens.json"), Path.home() / "tokens.json"):
44
+ if candidate.exists():
45
+ return candidate
46
+ return Path("tokens.json")
47
+
48
+
49
+ def _main(argv: Sequence[str] | None = None) -> int:
50
+ reconfigure_stdout_utf8()
51
+ args = _build_parser().parse_args(argv)
52
+ assert args.frontend in {"cli", "tui"}, "unsupported skeletal frontend"
53
+
54
+ api = OkLine.from_tokens_file(str(_token_path(args.tokens_file)))
55
+ try:
56
+ assert api.tokens.access_token, "no access token in the session file"
57
+ if args.frontend == "tui":
58
+ return run_tui(api)
59
+ if args.command == "list":
60
+ return run_list(api, args)
61
+ if args.command == "hist":
62
+ return run_history(api, args)
63
+ raise AssertionError("unsupported skeletal command")
64
+ finally:
65
+ api.close()
66
+
67
+
68
+ def main(argv: Sequence[str] | None = None) -> int:
69
+ """Run OmniLine, treating a closed downstream pipe as successful output."""
70
+ try:
71
+ return _main(argv)
72
+ except BrokenPipeError:
73
+ sys.stdout = open(os.devnull, "w", encoding="utf-8") # noqa: SIM115
74
+ return 0
75
+
76
+
77
+ if __name__ == "__main__":
78
+ raise SystemExit(main())
@@ -0,0 +1,129 @@
1
+ """Shared OkLine-backed operations for the three OmniLine frontends."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from okline.entities import Contact, Group
8
+
9
+ from .ufl import uflChat, uflContact, uflGroup, uflMessage
10
+
11
+ MESSAGE_BOX_BATCH_SIZE = 100
12
+
13
+
14
+ def message_boxes_by_id(api: Any, ids: list[str]) -> dict[str, dict[str, Any]]:
15
+ """Fetch listing metadata in bounded batches."""
16
+ boxes: dict[str, dict[str, Any]] = {}
17
+ for start in range(0, len(ids), MESSAGE_BOX_BATCH_SIZE):
18
+ result = api.get_message_boxes_by_ids(
19
+ ids[start : start + MESSAGE_BOX_BATCH_SIZE],
20
+ with_unread_count=True,
21
+ last_messages_count=1,
22
+ )
23
+ assert isinstance(result, dict)
24
+ batch = result.get("messageBoxesByIds", result.get("messageBoxes", {})) or {}
25
+ if isinstance(batch, dict):
26
+ boxes.update({str(mid): box for mid, box in batch.items() if isinstance(box, dict)})
27
+ else:
28
+ boxes.update(
29
+ {
30
+ str(box["id"]): box
31
+ for box in batch
32
+ if isinstance(box, dict) and box.get("id")
33
+ }
34
+ )
35
+ return boxes
36
+
37
+
38
+ def list_chats(api: Any) -> list[uflChat]:
39
+ """Return all contacts and groups as one polymorphic list."""
40
+ contact_ids = api.get_all_contact_ids() or []
41
+ contacts_result = api.get_contacts(contact_ids) if contact_ids else {"contacts": {}}
42
+ assert isinstance(contacts_result, dict)
43
+ contact_data = contacts_result.get("contacts", {})
44
+ assert isinstance(contact_data, dict)
45
+ contact_ids = list(contact_data)
46
+
47
+ all_chats = api.get_all_chat_mids() or {}
48
+ group_ids = list(
49
+ dict.fromkeys(
50
+ (all_chats.get("memberChatMids", []) or [])
51
+ + (all_chats.get("invitedChatMids", []) or [])
52
+ )
53
+ )
54
+ group_result = api.get_chats(group_ids) if group_ids else {"chats": []}
55
+ assert isinstance(group_result, dict)
56
+ group_data = group_result.get("chats", [])
57
+ assert isinstance(group_data, list)
58
+
59
+ boxes = message_boxes_by_id(api, contact_ids + group_ids)
60
+ chats: list[uflChat] = []
61
+ for mid, data in contact_data.items():
62
+ assert isinstance(data, dict)
63
+ chats.append(uflContact.from_okline(Contact.from_dict(data), boxes.get(mid, {})))
64
+ for data in group_data:
65
+ assert isinstance(data, dict)
66
+ group = Group.from_dict(data)
67
+ chats.append(uflGroup.from_okline(group, boxes.get(group.chat_mid, {})))
68
+ return chats
69
+
70
+
71
+ def find_chats(chats: list[uflChat], needle: str) -> list[uflChat]:
72
+ """Match a substring against the exact MID or display name."""
73
+ return [chat for chat in chats if needle in chat.id or needle in chat.name]
74
+
75
+
76
+ def resolve_contact_names(api: Any, mids: list[str]) -> dict[str, str]:
77
+ """Resolve sender MIDs through ``getContactsV2`` display-name fields."""
78
+ if not mids:
79
+ return {}
80
+ result = api.get_contacts(mids)
81
+ assert isinstance(result, dict)
82
+ contacts = result.get("contacts", {})
83
+ assert isinstance(contacts, dict)
84
+ names: dict[str, str] = {}
85
+ for mid, data in contacts.items():
86
+ assert isinstance(data, dict)
87
+ name = Contact.from_dict(data).name
88
+ if name:
89
+ names[str(mid)] = name
90
+ return names
91
+
92
+
93
+ def refresh_unread_counts(api: Any, chats: list[uflChat]) -> None:
94
+ """Refresh unread counts and latest timestamps without rebuilding chats."""
95
+ boxes = message_boxes_by_id(api, [chat.id for chat in chats])
96
+ for chat in chats:
97
+ box = boxes.get(chat.id, {})
98
+ chat.unread_count = chat.unread_from_box(box)
99
+ chat.last_message_time = chat.last_time_from_box(box)
100
+
101
+
102
+ def mark_chat_read(api: Any, chat: uflChat, messages: list[uflMessage]) -> None:
103
+ """Mark the selected chat read through its newest retrieved message."""
104
+ readable = [message for message in messages if message.id]
105
+ if not readable:
106
+ return
107
+ latest = max(readable, key=lambda message: message.created_time or -1)
108
+ api.send_chat_checked(chat.id, last_message_id=latest.id)
109
+ chat.unread_count = 0
110
+
111
+
112
+ def recent_messages(api: Any, chat: uflChat, count: int) -> list[uflMessage]:
113
+ """Fetch one recent page and decrypt sealed messages when possible."""
114
+ raw_messages = api.get_recent_messages(chat.id, count=count) or []
115
+ messages: list[uflMessage] = []
116
+ for raw in raw_messages:
117
+ assert isinstance(raw, dict)
118
+ decoded = raw
119
+ if raw.get("chunks"):
120
+ try:
121
+ decoded = api.decrypt_message(raw)
122
+ except Exception:
123
+ decoded = dict(raw)
124
+ decoded["text"] = "[encrypted]"
125
+ message = uflMessage.from_okline(decoded)
126
+ if decoded is not raw and decoded.get("text") != "[encrypted]":
127
+ message.raw.pop("chunks", None)
128
+ messages.append(message)
129
+ return messages
omniline/cli.py ADDED
@@ -0,0 +1,69 @@
1
+ """Command-line rendering and command handlers shared by future frontends."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import csv
6
+ import json
7
+ import sys
8
+ from argparse import Namespace
9
+ from typing import Any
10
+
11
+ from .chat_service import find_chats, list_chats, recent_messages
12
+ from .ufl import sort_chats, uflChat
13
+
14
+
15
+ def write_csv(chats: list[uflChat], stream: Any = sys.stdout) -> None:
16
+ """Write the compact conversation listing."""
17
+ out = csv.writer(stream, lineterminator="\n")
18
+ out.writerow(["id", "name", "kind", "last_message_time", "unread_count"])
19
+ for chat in chats:
20
+ out.writerow([
21
+ chat.id,
22
+ chat.name,
23
+ chat.kind,
24
+ chat.last_message_time,
25
+ "" if chat.unread_count is None else chat.unread_count,
26
+ ])
27
+
28
+
29
+ def write_json(chats: list[uflChat], stream: Any = sys.stdout) -> None:
30
+ json.dump([chat.to_dict(full=True) for chat in chats], stream, ensure_ascii=False)
31
+ stream.write("\n")
32
+
33
+
34
+ def write_matching_chats(chats: list[uflChat], stream: Any = sys.stdout) -> None:
35
+ """Write ambiguous matches without retrieving their histories."""
36
+ out = csv.writer(stream, lineterminator="\n")
37
+ for chat in chats:
38
+ out.writerow([chat.id, chat.name])
39
+
40
+
41
+ def write_history(messages: list[Any], stream: Any = sys.stdout) -> None:
42
+ for message in messages:
43
+ json.dump(message.to_dict(), stream, ensure_ascii=False)
44
+ stream.write("\n")
45
+
46
+
47
+ def run_list(api: Any, args: Namespace, stream: Any = sys.stdout) -> int:
48
+ assert not ((args.json or args.full) and args.csv), "--json/--full and --csv conflict"
49
+ chats = sort_chats(list_chats(api))
50
+ if args.sort == "name":
51
+ chats = sorted(chats, key=lambda chat: (chat.name.casefold(), chat.id))
52
+ if args.json or args.full:
53
+ write_json(chats, stream)
54
+ else:
55
+ write_csv(chats, stream)
56
+ return 0
57
+
58
+
59
+ def run_history(api: Any, args: Namespace, stream: Any = sys.stdout, error: Any = sys.stderr) -> int:
60
+ assert args.n >= 1, "-n must be positive"
61
+ matches = find_chats(list_chats(api), args.needle)
62
+ if not matches:
63
+ print(f'no chat matches "{args.needle}"', file=error)
64
+ return 1
65
+ if len(matches) > 1:
66
+ write_matching_chats(matches, stream)
67
+ return 0
68
+ write_history(recent_messages(api, matches[0], args.n), stream)
69
+ return 0
omniline/tui.py ADDED
@@ -0,0 +1,764 @@
1
+ """Read-only prompt_toolkit frontend for OmniLine."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import textwrap
6
+ from dataclasses import dataclass, field
7
+ from datetime import datetime
8
+ from typing import Any, cast
9
+
10
+ from prompt_toolkit.application import Application, get_app
11
+ from prompt_toolkit.buffer import Buffer
12
+ from prompt_toolkit.filters import Condition
13
+ from prompt_toolkit.key_binding import KeyBindings
14
+ from prompt_toolkit.layout import ConditionalContainer, HSplit, Layout, VSplit, Window
15
+ from prompt_toolkit.layout.controls import BufferControl, FormattedTextControl
16
+ from prompt_toolkit.layout.dimension import Dimension
17
+ from prompt_toolkit.layout.screen import Point
18
+ from prompt_toolkit.styles import Style
19
+
20
+ from .chat_service import (
21
+ list_chats,
22
+ mark_chat_read,
23
+ recent_messages,
24
+ refresh_unread_counts,
25
+ resolve_contact_names,
26
+ )
27
+ from .ufl import (
28
+ TAIPEI,
29
+ fit_display_name,
30
+ format_unread_count,
31
+ repeat_pattern,
32
+ sort_chats,
33
+ uflChat,
34
+ uflGroup,
35
+ uflMessage,
36
+ )
37
+
38
+
39
+ @dataclass
40
+ class TuiState:
41
+ """Mutable state kept separate from prompt_toolkit widgets."""
42
+
43
+ api: Any
44
+ chats: list[uflChat]
45
+ mode: str = "list"
46
+ cursor: int = 0
47
+ ordinary_offset: int = 0
48
+ query: str = ""
49
+ search_mode: str | None = None
50
+ search_buffer: Buffer = field(default_factory=Buffer)
51
+ compose_mode: str | None = None
52
+ compose_confirm: bool = False
53
+ compose_buffer: Buffer = field(default_factory=Buffer)
54
+ selected_chat: uflChat | None = None
55
+ messages: list[uflMessage] = field(default_factory=list)
56
+ content_lines: list[list[tuple[str, str]]] = field(default_factory=list)
57
+ content_offset: int = 0
58
+ content_query: str = ""
59
+ content_matches: list[tuple[int, int, int]] = field(default_factory=list)
60
+ content_cursor: int | None = None
61
+ content_cursor_line: int = 0
62
+ reply_targets: dict[int, str] = field(default_factory=dict)
63
+ search_direction: int = -1
64
+ sender_names: dict[str, str] = field(default_factory=dict)
65
+ app: Application | None = None
66
+
67
+ @property
68
+ def self_mid(self) -> str | None:
69
+ return getattr(self.api.tokens, "mid", None)
70
+
71
+ @property
72
+ def pinned(self) -> list[uflChat]:
73
+ return [chat for chat in self.chats if chat.pinned]
74
+
75
+ @property
76
+ def rows(self) -> list[uflChat]:
77
+ return sort_chats(self.chats, self.query)
78
+
79
+ @property
80
+ def ordinary(self) -> list[uflChat]:
81
+ return [chat for chat in self.rows if not chat.pinned]
82
+
83
+ @property
84
+ def displayed_count(self) -> int:
85
+ return len(self.rows)
86
+
87
+ @property
88
+ def current_chat(self) -> uflChat | None:
89
+ rows = self.rows
90
+ return rows[self.cursor] if rows and self.cursor < len(rows) else None
91
+
92
+ @property
93
+ def name_by_mid(self) -> dict[str, str]:
94
+ names = {chat.id: chat.name for chat in self.chats if chat.kind == "contact"}
95
+ names.update(self.sender_names)
96
+ return names
97
+
98
+ def invalidate(self) -> None:
99
+ if self.app:
100
+ self.app.invalidate()
101
+
102
+ def visible_ordinary_rows(self) -> int:
103
+ rows = get_app().output.get_size().rows
104
+ return max(1, rows - len(self.pinned) - 3 - (self.search_mode == "list"))
105
+
106
+ def ensure_cursor(self) -> None:
107
+ count = self.displayed_count
108
+ self.cursor = min(max(self.cursor, 0), max(0, count - 1))
109
+ favorite_count = len(self.pinned)
110
+ if self.cursor < favorite_count:
111
+ return
112
+ ordinary_index = self.cursor - favorite_count
113
+ visible = self.visible_ordinary_rows()
114
+ if ordinary_index < self.ordinary_offset:
115
+ self.ordinary_offset = ordinary_index
116
+ if ordinary_index >= self.ordinary_offset + visible:
117
+ self.ordinary_offset = ordinary_index - visible + 1
118
+ max_offset = max(0, len(self.ordinary) - visible)
119
+ self.ordinary_offset = min(self.ordinary_offset, max_offset)
120
+
121
+ def move_cursor(self, delta: int) -> None:
122
+ self.cursor += delta
123
+ self.ensure_cursor()
124
+ self.invalidate()
125
+
126
+ def begin_search(self) -> None:
127
+ self.search_mode = self.mode
128
+ self.search_buffer.reset()
129
+ self.search_buffer.text = self.query if self.mode == "list" else self.content_query
130
+ self.invalidate()
131
+
132
+ def submit_search(self) -> None:
133
+ text = self.search_buffer.text
134
+ mode = self.search_mode
135
+ self.search_mode = None
136
+ if mode == "list":
137
+ self.query = text
138
+ self.cursor = 0
139
+ self.ordinary_offset = 0
140
+ self.ensure_cursor()
141
+ elif mode == "content":
142
+ self.content_query = text
143
+ if text:
144
+ self.find_content_matches()
145
+ else:
146
+ self.content_matches = []
147
+ self.content_cursor = None
148
+ self.search_buffer.reset()
149
+ self.invalidate()
150
+
151
+ def cancel_search(self) -> None:
152
+ if self.search_mode == "list":
153
+ self.query = ""
154
+ self.cursor = 0
155
+ self.ordinary_offset = 0
156
+ self.search_mode = None
157
+ self.search_buffer.reset()
158
+ self.invalidate()
159
+
160
+ def restore_full_list(self) -> None:
161
+ """Remove a completed list filter; leave an already-full list unchanged."""
162
+ if self.mode == "list" and self.query:
163
+ self.query = ""
164
+ self.cursor = 0
165
+ self.ordinary_offset = 0
166
+ self.ensure_cursor()
167
+ self.invalidate()
168
+
169
+ def refresh_counts(self) -> None:
170
+ assert self.mode == "list"
171
+ refresh_unread_counts(self.api, self.chats)
172
+ self.ensure_cursor()
173
+ self.invalidate()
174
+
175
+ def enter_profile(self) -> None:
176
+ chat = self.current_chat
177
+ if chat is None:
178
+ return
179
+ self.selected_chat = chat
180
+ self.mode = "profile"
181
+ self.invalidate()
182
+
183
+ def toggle_pin(self) -> None:
184
+ assert self.mode == "profile"
185
+ chat = self.current_chat
186
+ assert chat is not None
187
+ old_id = chat.id
188
+ chat.pinned = not chat.pinned
189
+ rows = self.pinned + self.ordinary
190
+ self.cursor = next(index for index, row in enumerate(rows) if row.id == old_id)
191
+ self.ensure_cursor()
192
+ self.invalidate()
193
+
194
+ def enter_content(self) -> None:
195
+ chat = self.current_chat
196
+ if chat is None:
197
+ return
198
+ unread_count = chat.unread_count or 0
199
+ self.selected_chat = chat
200
+ self.messages = list(reversed(recent_messages(self.api, chat, 50)))
201
+ sender_mids = {
202
+ message.from_mid
203
+ for message in self.messages
204
+ if message.from_mid and message.from_mid != self.self_mid
205
+ }
206
+ self.sender_names.update(resolve_contact_names(self.api, sorted(sender_mids)))
207
+ self.content_lines = self.make_message_lines(chat, self.messages, unread_count)
208
+ mark_chat_read(self.api, chat, self.messages)
209
+ self.content_offset = max(0, len(self.content_lines) - self.content_height())
210
+ self.content_cursor_line = max(0, len(self.content_lines) - 1)
211
+ self.content_query = ""
212
+ self.content_matches = []
213
+ self.content_cursor = None
214
+ self.mode = "content"
215
+ self.invalidate()
216
+
217
+ def compose_message(self) -> None:
218
+ """Open the in-application compose dialog at the content cursor."""
219
+ assert self.mode == "content"
220
+ chat = self.selected_chat
221
+ assert chat is not None
222
+ reply_id = self.reply_targets.get(self.content_cursor_line)
223
+ is_new_message = self.content_cursor_line == len(self.content_lines) - 1
224
+ if not reply_id and not is_new_message:
225
+ return
226
+ self.compose_mode = "reply" if reply_id else "new"
227
+ self.compose_confirm = False
228
+ self.compose_buffer.reset()
229
+ self.invalidate()
230
+
231
+ def submit_compose(self) -> None:
232
+ """Advance compose input to confirmation, or cancel blank input."""
233
+ if not self.compose_buffer.text.strip():
234
+ self.cancel_compose()
235
+ return
236
+ self.compose_confirm = True
237
+ self.invalidate()
238
+
239
+ def confirm_compose(self) -> None:
240
+ assert self.compose_mode in {"new", "reply"}
241
+ chat = self.selected_chat
242
+ assert chat is not None
243
+ reply_id = self.reply_targets.get(self.content_cursor_line)
244
+ text = self.compose_buffer.text
245
+ if reply_id:
246
+ self.api.reply_text(chat.id, text, related_message_id=reply_id)
247
+ else:
248
+ self.api.send_text(chat.id, text)
249
+ self.cancel_compose()
250
+ self.enter_content()
251
+
252
+ def cancel_compose(self) -> None:
253
+ self.compose_mode = None
254
+ self.compose_confirm = False
255
+ self.compose_buffer.reset()
256
+ self.invalidate()
257
+
258
+ def leave_content(self) -> None:
259
+ self.mode = "list"
260
+ self.selected_chat = None
261
+ self.invalidate()
262
+
263
+ def content_height(self) -> int:
264
+ rows = get_app().output.get_size().rows
265
+ return max(1, rows - 2 - (self.search_mode == "content"))
266
+
267
+ def move_content(self, delta: int) -> None:
268
+ if not self.content_lines:
269
+ return
270
+ self.content_cursor_line = min(
271
+ max(0, self.content_cursor_line + delta), len(self.content_lines) - 1
272
+ )
273
+ self.reveal_line_cursor(1 if delta > 0 else -1)
274
+ self.invalidate()
275
+
276
+ def find_content_matches(self) -> None:
277
+ assert self.content_query
278
+ self.content_matches = []
279
+ for line_index, line in enumerate(self.content_lines):
280
+ text = "".join(part for _, part in line)
281
+ start = 0
282
+ while (match_start := text.find(self.content_query, start)) >= 0:
283
+ self.content_matches.append(
284
+ (line_index, match_start, match_start + len(self.content_query))
285
+ )
286
+ start = match_start + 1
287
+ if not self.content_matches:
288
+ self.content_cursor = None
289
+ return
290
+ # Content is oldest-first, so the last match is in the most recent
291
+ # matching message.
292
+ self.content_cursor = len(self.content_matches) - 1
293
+ self.reveal_content_cursor(0)
294
+
295
+ def next_content_match(self) -> None:
296
+ self.move_content_match(1)
297
+
298
+ def previous_content_match(self) -> None:
299
+ self.move_content_match(-1)
300
+
301
+ def move_content_match(self, step: int) -> None:
302
+ if not self.content_matches:
303
+ return
304
+ current = self.content_cursor if self.content_cursor is not None else 0
305
+ self.content_cursor = (current + step) % len(self.content_matches)
306
+ self.reveal_content_cursor(step)
307
+
308
+ def reveal_content_cursor(self, direction: int) -> None:
309
+ assert self.content_cursor is not None
310
+ self.content_cursor_line = self.content_matches[self.content_cursor][0]
311
+ self.reveal_line_cursor(direction)
312
+
313
+ def reveal_line_cursor(self, direction: int) -> None:
314
+ height = self.content_height()
315
+ maximum = max(0, len(self.content_lines) - height)
316
+ if self.content_offset <= self.content_cursor_line < self.content_offset + height:
317
+ return
318
+ if direction > 0:
319
+ # Forward search: keep the match at the top, delaying scrolling
320
+ # until the bottom of the available content is reached.
321
+ self.content_offset = min(self.content_cursor_line, maximum)
322
+ elif direction < 0:
323
+ # Backward search: keep the match at the bottom for the same reason.
324
+ self.content_offset = min(
325
+ max(0, self.content_cursor_line - height + 1), maximum
326
+ )
327
+ else:
328
+ # The initial match is the newest one; show it at the bottom.
329
+ self.content_offset = min(
330
+ max(0, self.content_cursor_line - height + 1), maximum
331
+ )
332
+
333
+ def content_cursor_position(self) -> Point | None:
334
+ if self.mode != "content":
335
+ return None
336
+ y = self.content_cursor_line - self.content_offset
337
+ return Point(x=0, y=y) if 0 <= y < self.content_height() else None
338
+
339
+ def make_message_lines(
340
+ self, chat: uflChat, messages: list[uflMessage], unread_count: int = 0
341
+ ) -> list[list[tuple[str, str]]]:
342
+ width = max(16, get_app().output.get_size().columns * 2 // 3)
343
+ text_width = max(1, width - 4)
344
+ names = self.name_by_mid
345
+ lines: list[list[tuple[str, str]]] = []
346
+ self.reply_targets = {}
347
+ previous_date = None
348
+ unread_boundary = len(messages) - max(0, unread_count)
349
+ unread_boundary = min(max(0, unread_boundary), len(messages))
350
+ lines.append([("class:boundary", "#" * width)])
351
+ for message_index, message in enumerate(messages):
352
+ own = message.from_mid == self.self_mid
353
+ if message_index == unread_boundary:
354
+ lines.append([("class:boundary", "." * width)])
355
+ message_date = (
356
+ datetime.fromtimestamp(message.created_time / 1000, TAIPEI).date()
357
+ if message.created_time is not None
358
+ else None
359
+ )
360
+ if message_date is not None:
361
+ if message_date != previous_date:
362
+ lines.append([("class:date", "📅 " + message_date.strftime("%m/%d"))])
363
+ previous_date = message_date
364
+ if not own:
365
+ sender = (
366
+ chat.name
367
+ if chat.kind == "contact"
368
+ else names.get(message.from_mid or "", message.from_mid or "?")
369
+ )
370
+ timestamp = (
371
+ datetime.fromtimestamp(message.created_time / 1000, TAIPEI).strftime("%H:%M ")
372
+ if message.created_time is not None
373
+ else " "
374
+ )
375
+ self.reply_targets[len(lines)] = message.id
376
+ lines.append([("", timestamp), ("class:sender", sender)])
377
+ text = message.text or f"[{message.availability}]"
378
+ for part in text.splitlines() or [""]:
379
+ wrapped = textwrap.wrap(part, width=text_width) or [""]
380
+ for line in wrapped:
381
+ padded = (" " * 4 + line) if own else (line.ljust(text_width) + " " * 4)
382
+ lines.append([("class:own" if own else "class:other", padded)])
383
+ lines.append([("class:anchor", repeat_pattern("* ", width))])
384
+ return lines
385
+
386
+ def list_fragments(self) -> list[tuple[str, str]]:
387
+ favorites = self.pinned
388
+ ordinary = self.ordinary
389
+ visible = ordinary[self.ordinary_offset : self.ordinary_offset + self.visible_ordinary_rows()]
390
+ rows = favorites + visible
391
+ first_ordinary = len(favorites) + self.ordinary_offset
392
+ width = max(12, get_app().output.get_size().columns // 3)
393
+ name_width = max(1, width - 4)
394
+ fragments: list[tuple[str, str]] = []
395
+ for local_index, chat in enumerate(rows):
396
+ global_index = local_index if local_index < len(favorites) else first_ordinary + local_index - len(favorites)
397
+ name, name_padding = fit_display_name(chat.name or chat.id, name_width)
398
+ count_field = format_unread_count(chat.unread_count)
399
+ selected = global_index == self.cursor
400
+ if selected and self.mode == "list":
401
+ style = "class:selected"
402
+ fragments.append((style, count_field + name + name_padding + "\n"))
403
+ elif selected:
404
+ count_style = "class:favorite" if chat.pinned else ""
405
+ name_style = "class:favorite-underline" if chat.pinned else "class:underline"
406
+ fragments.append((count_style, count_field))
407
+ if name_padding:
408
+ fragments.append((name_style, name))
409
+ fragments.append((count_style, name_padding + "\n"))
410
+ else:
411
+ fragments.append((name_style, name + "\n"))
412
+ else:
413
+ style = "class:favorite" if chat.pinned else ""
414
+ fragments.append((style, count_field + name + name_padding + "\n"))
415
+ return fragments or [("class:dim", "(no chats)\n")]
416
+
417
+
418
+ def profile_fragments(self) -> list[tuple[str, str]]:
419
+ chat = self.selected_chat or self.current_chat
420
+ assert chat is not None
421
+ raw = getattr(chat, "raw", {})
422
+ assert isinstance(raw, dict)
423
+ lines = [
424
+ ("class:title", chat.name or chat.id),
425
+ ("", f"kind: {chat.kind}\n"),
426
+ ("", f"mid: {chat.id}\n"),
427
+ ]
428
+ if isinstance(chat, uflGroup):
429
+ lines.append(("", f"members: {chat.member_count}\n"))
430
+ description = raw.get("chatName", "")
431
+ else:
432
+ description = raw.get("statusMessage", "")
433
+ if description:
434
+ lines.append(("", f"{description}\n"))
435
+ return lines
436
+
437
+ def content_fragments(self) -> list[tuple[str, str]]:
438
+ if self.mode == "profile":
439
+ return self.profile_fragments()
440
+ if self.mode != "content":
441
+ return [("class:dim", "Select a chat with Enter.\n")]
442
+ start = self.content_offset
443
+ end = start + self.content_height()
444
+ fragments: list[tuple[str, str]] = []
445
+ for index, line in enumerate(self.content_lines[start:end], start):
446
+ if index == self.content_cursor_line and index == len(self.content_lines) - 1:
447
+ line = [("class:anchor-cursor", text) for _, text in line]
448
+ elif index == self.content_cursor_line and all(
449
+ not text.strip() for _, text in line
450
+ ):
451
+ line = [("class:cursor-empty", text) for _, text in line]
452
+ line_matches = [
453
+ (match_start, match_end, match_index)
454
+ for match_index, (match_line, match_start, match_end) in enumerate(
455
+ self.content_matches
456
+ )
457
+ if match_line == index
458
+ ]
459
+ position = 0
460
+ for style, text in line:
461
+ end_position = position + len(text)
462
+ boundaries = {position, end_position}
463
+ for match_start, match_end, _ in line_matches:
464
+ if match_start < end_position and match_end > position:
465
+ boundaries.update(
466
+ bound for bound in (match_start, match_end)
467
+ if position <= bound <= end_position
468
+ )
469
+ ordered = sorted(boundaries)
470
+ for left, right in zip(ordered, ordered[1:]):
471
+ segment_style = style
472
+ for match_start, match_end, match_index in line_matches:
473
+ if left < match_end and right > match_start:
474
+ segment_style = (
475
+ "class:match"
476
+ if match_index == self.content_cursor
477
+ else "class:other-match"
478
+ )
479
+ break
480
+ fragments.append((segment_style, text[left - position : right - position]))
481
+ position = end_position
482
+ fragments.append(("", "\n"))
483
+ return fragments or [("class:dim", "(no messages)\n")]
484
+
485
+ def status_text(self) -> str:
486
+ if self.compose_mode:
487
+ return (
488
+ "y: confirm send n/Esc: cancel"
489
+ if self.compose_confirm
490
+ else "Enter: confirm Esc: cancel"
491
+ )
492
+ if self.search_mode:
493
+ return "Enter: submit Esc: cancel " + self.search_buffer.text
494
+ if self.mode == "list":
495
+ return "/ search Enter/l: messages p: profile q: quit"
496
+ if self.mode == "profile":
497
+ return "h/Left/Esc: back"
498
+ return "/ search n: next, p: previous R: send/reply h/Left/Esc: chats q: quit"
499
+
500
+
501
+ def _key_bindings(
502
+ state: TuiState,
503
+ search_window: Window,
504
+ list_window: Window,
505
+ content_window: Window,
506
+ compose_window: Window,
507
+ ) -> KeyBindings:
508
+ """Bind keys by active panel; profile mode intentionally has no navigation."""
509
+ keys = KeyBindings()
510
+ list_active = Condition(
511
+ lambda: state.search_mode is None and state.compose_mode is None and state.mode == "list"
512
+ )
513
+ content_active = Condition(
514
+ lambda: state.search_mode is None
515
+ and state.compose_mode is None
516
+ and state.mode == "content"
517
+ )
518
+ panel_active = Condition(
519
+ lambda: state.search_mode is None
520
+ and state.compose_mode is None
521
+ and state.mode in {"list", "content", "profile"}
522
+ )
523
+ searchable = Condition(
524
+ lambda: state.search_mode is None
525
+ and state.compose_mode is None
526
+ and state.mode in {"list", "content"}
527
+ )
528
+
529
+ def focus_list(event: Any) -> None:
530
+ event.app.layout.focus(list_window)
531
+
532
+ def focus_content(event: Any) -> None:
533
+ event.app.layout.focus(content_window)
534
+
535
+ def focus_compose(event: Any) -> None:
536
+ event.app.layout.focus(compose_window)
537
+
538
+ @keys.add("up", filter=list_active)
539
+ @keys.add("k", filter=list_active)
540
+ def _list_up(event: Any) -> None:
541
+ state.move_cursor(-1)
542
+
543
+ @keys.add("down", filter=list_active)
544
+ @keys.add("j", filter=list_active)
545
+ def _list_down(event: Any) -> None:
546
+ state.move_cursor(1)
547
+
548
+ @keys.add("up", filter=content_active)
549
+ @keys.add("k", filter=content_active)
550
+ def _content_up(event: Any) -> None:
551
+ state.move_content(-1)
552
+
553
+ @keys.add("down", filter=content_active)
554
+ @keys.add("j", filter=content_active)
555
+ def _content_down(event: Any) -> None:
556
+ state.move_content(1)
557
+
558
+ @keys.add("pageup", filter=list_active)
559
+ def _list_page_up(event: Any) -> None:
560
+ state.move_cursor(-state.visible_ordinary_rows())
561
+
562
+ @keys.add("pagedown", filter=list_active)
563
+ def _list_page_down(event: Any) -> None:
564
+ state.move_cursor(state.visible_ordinary_rows())
565
+
566
+ @keys.add("pageup", filter=content_active)
567
+ def _content_page_up(event: Any) -> None:
568
+ state.move_content(-state.content_height())
569
+
570
+ @keys.add("pagedown", filter=content_active)
571
+ def _content_page_down(event: Any) -> None:
572
+ state.move_content(state.content_height())
573
+
574
+ @keys.add("/", filter=searchable)
575
+ def _search(event: Any) -> None:
576
+ state.begin_search()
577
+ event.app.layout.focus(search_window)
578
+
579
+ @keys.add("enter")
580
+ def _enter(event: Any) -> None:
581
+ if state.compose_mode:
582
+ if state.compose_confirm:
583
+ state.confirm_compose()
584
+ else:
585
+ state.submit_compose()
586
+ elif state.search_mode:
587
+ state.submit_search()
588
+ focus_list(event) if state.mode == "list" else focus_content(event)
589
+ elif state.mode == "list" and state.current_chat is not None:
590
+ state.enter_content()
591
+ focus_content(event)
592
+
593
+ @keys.add("escape")
594
+ def _escape(event: Any) -> None:
595
+ if state.compose_mode:
596
+ state.cancel_compose()
597
+ focus_content(event)
598
+ elif state.search_mode:
599
+ state.cancel_search()
600
+ elif state.mode == "list":
601
+ state.restore_full_list()
602
+ else:
603
+ state.leave_content()
604
+ focus_list(event)
605
+
606
+ @keys.add("left", filter=panel_active)
607
+ @keys.add("h", filter=panel_active)
608
+ def _back(event: Any) -> None:
609
+ if state.mode == "list":
610
+ state.restore_full_list()
611
+ else:
612
+ state.leave_content()
613
+ focus_list(event)
614
+
615
+ @keys.add("right", filter=list_active)
616
+ @keys.add("l", filter=list_active)
617
+ def _forward(event: Any) -> None:
618
+ if state.current_chat is not None:
619
+ state.enter_content()
620
+ focus_content(event)
621
+
622
+ @keys.add("p", filter=list_active)
623
+ def _profile(event: Any) -> None:
624
+ if state.current_chat is not None:
625
+ state.enter_profile()
626
+ focus_content(event)
627
+
628
+ @keys.add("p", filter=content_active)
629
+ def _previous_match(event: Any) -> None:
630
+ if state.content_query:
631
+ state.previous_content_match()
632
+ state.invalidate()
633
+
634
+ @keys.add("R", filter=list_active)
635
+ def _refresh(event: Any) -> None:
636
+ state.refresh_counts()
637
+
638
+ @keys.add("n", filter=content_active)
639
+ def _next_match(event: Any) -> None:
640
+ if state.content_query:
641
+ state.next_content_match()
642
+ state.invalidate()
643
+
644
+ @keys.add("R", filter=content_active)
645
+ def _compose(event: Any) -> None:
646
+ state.compose_message()
647
+ if state.compose_mode:
648
+ focus_compose(event)
649
+
650
+ @keys.add("y", filter=Condition(lambda: state.compose_confirm))
651
+ def _confirm_compose(event: Any) -> None:
652
+ state.confirm_compose()
653
+ focus_content(event)
654
+
655
+ @keys.add("n", filter=Condition(lambda: state.compose_confirm))
656
+ def _cancel_compose(event: Any) -> None:
657
+ state.cancel_compose()
658
+ focus_content(event)
659
+
660
+ @keys.add(
661
+ "q",
662
+ filter=Condition(
663
+ lambda: state.search_mode is None
664
+ and state.compose_mode is None
665
+ and state.mode in {"list", "content"}
666
+ ),
667
+ )
668
+ def _quit_or_back(event: Any) -> None:
669
+ if state.mode == "list":
670
+ event.app.exit()
671
+ else:
672
+ state.leave_content()
673
+ focus_list(event)
674
+
675
+ @keys.add("c-c")
676
+ def _ctrl_c(event: Any) -> None:
677
+ event.app.exit()
678
+
679
+ return keys
680
+
681
+
682
+ def run_tui(api: Any) -> int:
683
+ """Run the read-only TUI against an already-authenticated API client."""
684
+ state = TuiState(api=api, chats=list_chats(api))
685
+ list_window = Window(
686
+ FormattedTextControl(cast(Any, state.list_fragments), focusable=True, show_cursor=False),
687
+ width=Dimension(weight=1),
688
+ wrap_lines=False,
689
+ style="class:list-panel",
690
+ )
691
+ content_window = Window(
692
+ FormattedTextControl(
693
+ cast(Any, state.content_fragments),
694
+ focusable=True,
695
+ get_cursor_position=state.content_cursor_position,
696
+ ),
697
+ width=Dimension(weight=2),
698
+ wrap_lines=False,
699
+ style="class:content-panel",
700
+ cursorline=True,
701
+ )
702
+ search_window = Window(
703
+ BufferControl(state.search_buffer),
704
+ height=1,
705
+ style="class:search",
706
+ wrap_lines=False,
707
+ )
708
+ compose_window = Window(
709
+ BufferControl(state.compose_buffer),
710
+ height=1,
711
+ style="class:compose",
712
+ wrap_lines=False,
713
+ )
714
+ status_window = Window(
715
+ FormattedTextControl(lambda: [("class:status", state.status_text())]),
716
+ height=1,
717
+ )
718
+ body = HSplit([
719
+ VSplit([
720
+ list_window,
721
+ Window(char="|", width=Dimension.exact(1), style="class:divider"),
722
+ content_window,
723
+ ]),
724
+ Window(FormattedTextControl(lambda: []), height=0),
725
+ ConditionalContainer(search_window, Condition(lambda: state.search_mode is not None)),
726
+ ConditionalContainer(compose_window, Condition(lambda: state.compose_mode is not None)),
727
+ status_window,
728
+ ])
729
+ style = Style.from_dict({
730
+ "list-panel": "bg:#202020",
731
+ "content-panel": "bg:#101010",
732
+ "divider": "#666666",
733
+ "selected": "reverse",
734
+ "favorite": "bold",
735
+ "underline": "underline",
736
+ "favorite-underline": "bold underline",
737
+ "title": "bold underline",
738
+ "sender": "underline",
739
+ "date": "bold",
740
+ "boundary": "#666666",
741
+ "anchor": "#666666",
742
+ "anchor-cursor": "reverse",
743
+ "cursor-empty": "underline",
744
+ "own": "#88ccff",
745
+ "other": "#eeeeee",
746
+ "match": "reverse #ffff00",
747
+ "other-match": "bold",
748
+ "status": "reverse",
749
+ "search": "#ffffff bg:#303030",
750
+ "compose": "#ffffff bg:#303030",
751
+ "dim": "#888888",
752
+ })
753
+ application: Application[None] = Application(
754
+ layout=Layout(body, focused_element=list_window),
755
+ key_bindings=_key_bindings(
756
+ state, search_window, list_window, content_window, compose_window
757
+ ),
758
+ style=style,
759
+ full_screen=True,
760
+ mouse_support=False,
761
+ )
762
+ state.app = application
763
+ application.run()
764
+ return 0
omniline/ufl.py ADDED
@@ -0,0 +1,212 @@
1
+ """User-facing OmniLine models and presentation-neutral helpers.
2
+
3
+ The CLI, TUI, and future web frontend should exchange these objects rather than
4
+ wire dictionaries or prompt_toolkit-specific fragments.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from abc import ABC, abstractmethod
10
+ from dataclasses import dataclass, field
11
+ from datetime import datetime
12
+ from typing import Any
13
+ from zoneinfo import ZoneInfo
14
+
15
+ from wcwidth import wcswidth
16
+
17
+ from okline.entities import Contact, Group
18
+
19
+ TAIPEI = ZoneInfo("Asia/Taipei")
20
+
21
+
22
+ def _cell_width(text: str) -> int:
23
+ return max(0, wcswidth(text))
24
+
25
+
26
+ def repeat_pattern(pattern: str, width: int) -> str:
27
+ """Repeat a configured text pattern until it fills ``width`` cells."""
28
+ assert pattern
29
+ assert width >= 0
30
+ result = ""
31
+ while _cell_width(result + pattern) <= width:
32
+ result += pattern
33
+ for char in pattern:
34
+ if _cell_width(result + char) > width:
35
+ break
36
+ result += char
37
+ return result
38
+
39
+
40
+ def fit_display_name(name: str, width: int) -> tuple[str, str]:
41
+ """Return ``(visible_name, trailing_padding)`` by terminal-cell width."""
42
+ if _cell_width(name) <= width:
43
+ return name, " " * (width - _cell_width(name))
44
+ if width == 1:
45
+ return "…", ""
46
+ visible = ""
47
+ for char in name:
48
+ if _cell_width(visible + char + "…") > width:
49
+ break
50
+ visible += char
51
+ display = visible + "…"
52
+ return display, " " * (width - _cell_width(display))
53
+
54
+
55
+ def format_unread_count(count: int | None) -> str:
56
+ """Return the fixed four-cell unread-count field."""
57
+ count = count or 0
58
+ return " " if count == 0 else "*** " if count > 999 else f"{count:3d} "
59
+
60
+
61
+ def sort_chats(chats: list[uflChat], query: str = "") -> list[uflChat]:
62
+ """Keep pinned chats first and sort the ordinary subset by recency."""
63
+ pinned = [chat for chat in chats if chat.pinned]
64
+ ordinary = [chat for chat in chats if not chat.pinned]
65
+ if query:
66
+ ordinary = [chat for chat in ordinary if query in chat.name]
67
+ ordinary.sort(key=lambda chat: chat.last_message_time or "", reverse=True)
68
+ return pinned + ordinary
69
+
70
+
71
+ class uflChat(ABC): # noqa: N801 - public name intentionally follows the design brief
72
+ """A user-facing conversation, either a contact or a group."""
73
+
74
+ id: str
75
+ name: str
76
+ last_message_time: str
77
+ unread_count: int | None
78
+ pinned: bool
79
+
80
+ @property
81
+ @abstractmethod
82
+ def kind(self) -> str:
83
+ """Return ``contact`` or ``group``."""
84
+
85
+ @staticmethod
86
+ def last_time_from_box(box: dict[str, Any] | None) -> str:
87
+ delivered = box.get("lastDeliveredMessageId") if box else None
88
+ millis = delivered.get("deliveredTime") if isinstance(delivered, dict) else None
89
+ if millis in (None, ""):
90
+ return ""
91
+ return datetime.fromtimestamp(int(millis) / 1000, TAIPEI).isoformat()
92
+
93
+ @staticmethod
94
+ def unread_from_box(box: dict[str, Any] | None) -> int | None:
95
+ value = box.get("unreadCount") if box else None
96
+ return int(value) if value not in (None, "") else None
97
+
98
+ @staticmethod
99
+ def pinned_from_data(*data: dict[str, Any] | None) -> bool:
100
+ for item in data:
101
+ if not item:
102
+ continue
103
+ if item.get("isFavorite") is not None:
104
+ return bool(item["isFavorite"])
105
+ if item.get("favorite") is not None:
106
+ return bool(item["favorite"])
107
+ if item.get("favoriteTimestamp") not in (None, "", 0, "0"):
108
+ return True
109
+ return False
110
+
111
+ def to_dict(self, *, full: bool = False) -> dict[str, Any]:
112
+ result = dict(self.__dict__) if full else {
113
+ "id": self.id,
114
+ "name": self.name,
115
+ "kind": self.kind,
116
+ "last_message_time": self.last_message_time,
117
+ "unread_count": self.unread_count,
118
+ }
119
+ result["kind"] = self.kind
120
+ return result
121
+
122
+
123
+ @dataclass
124
+ class uflContact(uflChat): # noqa: N801 - public name intentionally follows the design brief
125
+ id: str
126
+ name: str
127
+ last_message_time: str = ""
128
+ unread_count: int | None = None
129
+ pinned: bool = False
130
+ raw: dict[str, Any] = field(default_factory=dict)
131
+
132
+ @property
133
+ def kind(self) -> str:
134
+ return "contact"
135
+
136
+ @classmethod
137
+ def from_okline(cls, contact: Contact, box: dict[str, Any]) -> uflContact:
138
+ return cls(
139
+ id=contact.mid,
140
+ name=contact.name,
141
+ last_message_time=cls.last_time_from_box(box),
142
+ unread_count=cls.unread_from_box(box),
143
+ pinned=cls.pinned_from_data(contact.raw, box),
144
+ raw=contact.raw,
145
+ )
146
+
147
+
148
+ @dataclass
149
+ class uflGroup(uflChat): # noqa: N801 - public name intentionally follows the design brief
150
+ id: str
151
+ name: str
152
+ last_message_time: str = ""
153
+ unread_count: int | None = None
154
+ pinned: bool = False
155
+ member_count: int = 0
156
+ raw: dict[str, Any] = field(default_factory=dict)
157
+
158
+ @property
159
+ def kind(self) -> str:
160
+ return "group"
161
+
162
+ @classmethod
163
+ def from_okline(cls, group: Group, box: dict[str, Any]) -> uflGroup:
164
+ return cls(
165
+ id=group.chat_mid,
166
+ name=group.name,
167
+ last_message_time=cls.last_time_from_box(box),
168
+ unread_count=cls.unread_from_box(box),
169
+ pinned=cls.pinned_from_data(group.raw, box),
170
+ member_count=group.member_count,
171
+ raw=group.raw,
172
+ )
173
+
174
+
175
+ @dataclass
176
+ class uflMessage: # noqa: N801 - public name intentionally follows the design brief
177
+ id: str = ""
178
+ from_mid: str | None = None
179
+ to: str | None = None
180
+ created_time: int | None = None
181
+ delivered_time: int | None = None
182
+ text: str | None = None
183
+ content_type: int = 0
184
+ availability: str = "unsupported"
185
+ raw: dict[str, Any] = field(default_factory=dict)
186
+
187
+ @classmethod
188
+ def from_okline(cls, message: dict[str, Any]) -> uflMessage:
189
+ created = message.get("createdTime")
190
+ delivered = message.get("deliveredTime")
191
+ text = message.get("text")
192
+ content_type = int(message.get("contentType", 0) or 0)
193
+ availability = (
194
+ "readable" if text is not None else
195
+ "encrypted" if message.get("chunks") else "unsupported"
196
+ )
197
+ return cls(
198
+ id=str(message.get("id", "")),
199
+ from_mid=message.get("from"),
200
+ to=message.get("to"),
201
+ created_time=int(created) if created not in (None, "") else None,
202
+ delivered_time=int(delivered) if delivered not in (None, "") else None,
203
+ text=text,
204
+ content_type=content_type,
205
+ availability=availability,
206
+ raw=dict(message),
207
+ )
208
+
209
+ def to_dict(self) -> dict[str, Any]:
210
+ result = dict(self.__dict__)
211
+ result["raw"] = dict(self.raw)
212
+ return result
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: omniline
3
+ Version: 0.1
4
+ Summary: User-friendly CLI and terminal UI for LINE Messenger, powered by OkLine.
5
+ Author: Greg Chao-Kuei Hung
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ckhung/OmniLine
8
+ Project-URL: Documentation, https://github.com/ckhung/OmniLine/tree/main/docs
9
+ Project-URL: Repository, https://github.com/ckhung/OmniLine
10
+ Project-URL: Issues, https://github.com/ckhung/OmniLine/issues
11
+ Project-URL: Changelog, https://github.com/ckhung/OmniLine/blob/main/CHANGELOG.md
12
+ Keywords: line,line-messenger,line-api,line-bot,line-messenger-api,line-chrome,line-chrome-extension-api,line-client,line-sdk,python-line,unofficial-line,line-personal-account,line-qr-login,line-login-qr-code,letter-sealing,line-e2ee,e2ee,end-to-end-encryption,line-notify-alternative,linepy-alternative,line-selfbot,line-automation,line-mcp,chatbot,automation,messaging,reverse-engineering,chrome-extension,thrift,x-hmac,okline
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: End Users/Desktop
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Natural Language :: Chinese (Traditional)
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Communications :: Chat
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Classifier: Topic :: Internet :: WWW/HTTP
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: >=3.9
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Requires-Dist: requests>=2.28
32
+ Requires-Dist: cryptography>=41.0
33
+ Requires-Dist: qrcode>=7.0
34
+ Requires-Dist: prompt-toolkit>=3.0.52
35
+ Requires-Dist: wcwidth>=0.9.4
36
+ Requires-Dist: okline>=2.7.0
37
+ Provides-Extra: test
38
+ Requires-Dist: pytest>=7.0; extra == "test"
39
+ Provides-Extra: dev
40
+ Requires-Dist: pytest>=7.0; extra == "dev"
41
+ Requires-Dist: ruff>=0.6; extra == "dev"
42
+ Requires-Dist: mypy>=1.8; extra == "dev"
43
+ Requires-Dist: types-requests; extra == "dev"
44
+ Requires-Dist: pre-commit>=3.5; extra == "dev"
45
+ Requires-Dist: build>=1.0; extra == "dev"
46
+ Requires-Dist: twine>=5.0; extra == "dev"
47
+ Dynamic: license-file
48
+
49
+ # OmniLine
50
+
51
+ OmniLine is a combination of 3 frontends for LINE, a popular messaging app in Taiwan. OmniLine only provides the user interfaces; the underlying heavy work of authentication and communication is provided by [OkLine](https://nicedayzc.github.io/OkLine/) and created by nicedayzc. The 3 frontends are:
52
+ - **omniline cli**: a barebone command line version mostly used for testing
53
+ - **omniline tui**: a terminal user interface more or less usable for text-reading and sending
54
+ - **omniline web**: to be written
55
+
56
+ ## License
57
+
58
+ [MIT](LICENSE)
@@ -0,0 +1,12 @@
1
+ omniline/__init__.py,sha256=PFJhkXXpq-d8FfRzABvfbz81WgK0_N27hLRvMBHkSYc,62
2
+ omniline/__main__.py,sha256=Xx7XqKGShnh4-dP1GS6GcES_xYgOHR1Eqc9n8kVqFnw,2944
3
+ omniline/chat_service.py,sha256=UAiIXSN0cHZ6RYmu2KZTbhZQxkwA8qHocYXhGf5AjEA,4887
4
+ omniline/cli.py,sha256=Byvdre9i6nBtEwHc9OGqC5Hf3OkDJpDCvrHBpbfqaYY,2346
5
+ omniline/tui.py,sha256=cVAVv3_XfC16ePV2TNKoVkuEo2_4U3Etx6otaDhpuJ0,28241
6
+ omniline/ufl.py,sha256=tyG1-5_Ogxqo99AA_WihNtaVjLVFG0HiwCoCb-05hYo,6860
7
+ omniline-0.1.dist-info/licenses/LICENSE,sha256=jBCLcYxHBA4AOtduTE6Dq6r2YywG2-BhwlBRpk_F-Dw,1337
8
+ omniline-0.1.dist-info/METADATA,sha256=Hzw4TW4SU5PgPxEXCB2FLrmeTd6G8eeqTqwa-zhxnMU,2896
9
+ omniline-0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
10
+ omniline-0.1.dist-info/entry_points.txt,sha256=p25X3d2CMhVKnCFAGLVUcNlzLWnN5-DEHZbwU35kcPo,52
11
+ omniline-0.1.dist-info/top_level.txt,sha256=nwoSoDZsp5mqyBn0hSo9emfCIXLkzXRQuyOmc3XL5tI,9
12
+ omniline-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ omniline = omniline.__main__:main
@@ -0,0 +1,28 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OkLine contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ NOTE: OkLine is an unofficial, independent project. It is not affiliated with,
26
+ endorsed by, or sponsored by LINE Corporation. "LINE" is a trademark of its
27
+ respective owner. Use it only with your own account and in compliance with
28
+ LINE's Terms of Service.
@@ -0,0 +1 @@
1
+ omniline