prettynb-tui 0.1.0a1__tar.gz
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.
- prettynb_tui-0.1.0a1/LICENSE +21 -0
- prettynb_tui-0.1.0a1/PKG-INFO +55 -0
- prettynb_tui-0.1.0a1/README.md +40 -0
- prettynb_tui-0.1.0a1/pyproject.toml +28 -0
- prettynb_tui-0.1.0a1/pyproject.toml.orig +28 -0
- prettynb_tui-0.1.0a1/src/prettynb_tui/__init__.py +5 -0
- prettynb_tui-0.1.0a1/src/prettynb_tui/__main__.py +3 -0
- prettynb_tui-0.1.0a1/src/prettynb_tui/cli.py +96 -0
- prettynb_tui-0.1.0a1/src/prettynb_tui/workbench.py +135 -0
- prettynb_tui-0.1.0a1/tests/test_native_review.py +86 -0
- prettynb_tui-0.1.0a1/tests/test_notebook.py +42 -0
- prettynb_tui-0.1.0a1/tests/test_profiles.py +77 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ella Inng
|
|
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.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prettynb-tui
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Terminal workbench alpha for Pretty Notebook
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: prettynb>=0.18.0,<0.19
|
|
8
|
+
Requires-Dist: function-sequence[terminal]>=0.2.0,<0.3
|
|
9
|
+
Requires-Dist: hidden-moves[composition]>=0.2.0,<0.3
|
|
10
|
+
Requires-Dist: headless-spreadsheets>=0.1.1,<0.2
|
|
11
|
+
Requires-Python: >=3.14
|
|
12
|
+
Project-URL: Source, https://github.com/wispsy/prettynb/tree/main/apps/tui
|
|
13
|
+
Project-URL: Project, https://github.com/orgs/wispsy/projects/20
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Pretty Notebook TUI alpha
|
|
17
|
+
|
|
18
|
+
A separate Python 3.14 application for terminal workflows. It carries forward
|
|
19
|
+
the Peaches 0.1.0 Text Workbench over Function Sequence, Hidden Moves, and
|
|
20
|
+
Carets. The Pretty Notebook library and web app have their own packages.
|
|
21
|
+
|
|
22
|
+
Install the opt-in PyPI alpha on Python 3.14:
|
|
23
|
+
|
|
24
|
+
python -m pip install prettynb-tui==0.1.0a1
|
|
25
|
+
|
|
26
|
+
For development, install both source projects from the repository root:
|
|
27
|
+
|
|
28
|
+
python -m pip install -e . -e ./apps/tui
|
|
29
|
+
|
|
30
|
+
The text commands retain the workflow's report, Markdown table, and terminal
|
|
31
|
+
review paths:
|
|
32
|
+
|
|
33
|
+
prettynb-tui inspect
|
|
34
|
+
prettynb-tui report ' Hello WORLD ' --checkpoint progress.json --pace function
|
|
35
|
+
prettynb-tui report ' Hello WORLD ' --checkpoint progress.json --resume
|
|
36
|
+
prettynb-tui markdown --text ' Hello WORLD ' --text ' More words '
|
|
37
|
+
prettynb-tui review ' Hello WORLD ' --checkpoint review.json
|
|
38
|
+
|
|
39
|
+
Interactive review requires a POSIX terminal. It prompts for both selected
|
|
40
|
+
operations. Start new checkpoints in this alpha because the Function Sequence
|
|
41
|
+
resolver and fingerprints differ from the original Peaches release.
|
|
42
|
+
|
|
43
|
+
Local notebook commands expose a small read-only path through existing notebook
|
|
44
|
+
operations:
|
|
45
|
+
|
|
46
|
+
prettynb-tui search ./notes 'keyword'
|
|
47
|
+
prettynb-tui preview ./notes MyNote
|
|
48
|
+
prettynb-tui move-plan ./notes MyNote.md archive/MyNote.md
|
|
49
|
+
|
|
50
|
+
The move plan invokes Pretty Notebook's checked dry run. Notebook permissions,
|
|
51
|
+
identities and link rules remain those of the underlying API.
|
|
52
|
+
|
|
53
|
+
The original workbench and release remain available at
|
|
54
|
+
[Peaches v0.1.0](https://github.com/wispsy/peaches/tree/v0.1.0). Current work is
|
|
55
|
+
tracked under [TUI-01](https://github.com/wispsy/prettynb/issues/280).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Pretty Notebook TUI alpha
|
|
2
|
+
|
|
3
|
+
A separate Python 3.14 application for terminal workflows. It carries forward
|
|
4
|
+
the Peaches 0.1.0 Text Workbench over Function Sequence, Hidden Moves, and
|
|
5
|
+
Carets. The Pretty Notebook library and web app have their own packages.
|
|
6
|
+
|
|
7
|
+
Install the opt-in PyPI alpha on Python 3.14:
|
|
8
|
+
|
|
9
|
+
python -m pip install prettynb-tui==0.1.0a1
|
|
10
|
+
|
|
11
|
+
For development, install both source projects from the repository root:
|
|
12
|
+
|
|
13
|
+
python -m pip install -e . -e ./apps/tui
|
|
14
|
+
|
|
15
|
+
The text commands retain the workflow's report, Markdown table, and terminal
|
|
16
|
+
review paths:
|
|
17
|
+
|
|
18
|
+
prettynb-tui inspect
|
|
19
|
+
prettynb-tui report ' Hello WORLD ' --checkpoint progress.json --pace function
|
|
20
|
+
prettynb-tui report ' Hello WORLD ' --checkpoint progress.json --resume
|
|
21
|
+
prettynb-tui markdown --text ' Hello WORLD ' --text ' More words '
|
|
22
|
+
prettynb-tui review ' Hello WORLD ' --checkpoint review.json
|
|
23
|
+
|
|
24
|
+
Interactive review requires a POSIX terminal. It prompts for both selected
|
|
25
|
+
operations. Start new checkpoints in this alpha because the Function Sequence
|
|
26
|
+
resolver and fingerprints differ from the original Peaches release.
|
|
27
|
+
|
|
28
|
+
Local notebook commands expose a small read-only path through existing notebook
|
|
29
|
+
operations:
|
|
30
|
+
|
|
31
|
+
prettynb-tui search ./notes 'keyword'
|
|
32
|
+
prettynb-tui preview ./notes MyNote
|
|
33
|
+
prettynb-tui move-plan ./notes MyNote.md archive/MyNote.md
|
|
34
|
+
|
|
35
|
+
The move plan invokes Pretty Notebook's checked dry run. Notebook permissions,
|
|
36
|
+
identities and link rules remain those of the underlying API.
|
|
37
|
+
|
|
38
|
+
The original workbench and release remain available at
|
|
39
|
+
[Peaches v0.1.0](https://github.com/wispsy/peaches/tree/v0.1.0). Current work is
|
|
40
|
+
tracked under [TUI-01](https://github.com/wispsy/prettynb/issues/280).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "prettynb-tui"
|
|
3
|
+
version = "0.1.0a1"
|
|
4
|
+
description = "Terminal workbench alpha for Pretty Notebook"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.14"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"prettynb>=0.18.0,<0.19",
|
|
11
|
+
"function-sequence[terminal]>=0.2.0,<0.3",
|
|
12
|
+
"hidden-moves[composition]>=0.2.0,<0.3",
|
|
13
|
+
"headless-spreadsheets>=0.1.1,<0.2",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
prettynb-tui = "prettynb_tui.cli:main"
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Source = "https://github.com/wispsy/prettynb/tree/main/apps/tui"
|
|
21
|
+
Project = "https://github.com/orgs/wispsy/projects/20"
|
|
22
|
+
|
|
23
|
+
[build-system]
|
|
24
|
+
requires = ["uv_build>=0.13.6,<0.14"]
|
|
25
|
+
build-backend = "uv_build"
|
|
26
|
+
|
|
27
|
+
[tool.uv.build-backend]
|
|
28
|
+
source-include = ["tests/*.py"]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "prettynb-tui"
|
|
3
|
+
version = "0.1.0a1"
|
|
4
|
+
description = "Terminal workbench alpha for Pretty Notebook"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.14"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"prettynb>=0.18.0,<0.19",
|
|
11
|
+
"function-sequence[terminal]>=0.2.0,<0.3",
|
|
12
|
+
"hidden-moves[composition]>=0.2.0,<0.3",
|
|
13
|
+
"headless-spreadsheets>=0.1.1,<0.2",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
prettynb-tui = "prettynb_tui.cli:main"
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Source = "https://github.com/wispsy/prettynb/tree/main/apps/tui"
|
|
21
|
+
Project = "https://github.com/orgs/wispsy/projects/20"
|
|
22
|
+
|
|
23
|
+
[build-system]
|
|
24
|
+
requires = ["uv_build>=0.13.6,<0.14"]
|
|
25
|
+
build-backend = "uv_build"
|
|
26
|
+
|
|
27
|
+
[tool.uv.build-backend]
|
|
28
|
+
source-include = ["tests/*.py"]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Terminal workflow alpha and read-only notebook commands."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import asyncio
|
|
5
|
+
import json
|
|
6
|
+
import sys
|
|
7
|
+
from dataclasses import asdict
|
|
8
|
+
|
|
9
|
+
from .workbench import TextWorkbench
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _parser() -> argparse.ArgumentParser:
|
|
13
|
+
parser = argparse.ArgumentParser(prog="prettynb-tui", description=__doc__)
|
|
14
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
15
|
+
commands.add_parser("inspect", help="Inspect the text workflow")
|
|
16
|
+
report = commands.add_parser("report", help="Normalize and report text")
|
|
17
|
+
review = commands.add_parser(
|
|
18
|
+
"review", help="Review the text workflow in the terminal"
|
|
19
|
+
)
|
|
20
|
+
for command in (report, review):
|
|
21
|
+
command.add_argument("text")
|
|
22
|
+
command.add_argument("--checkpoint", required=command is review)
|
|
23
|
+
report.add_argument("--pace", default="auto")
|
|
24
|
+
report.add_argument("--resume", action="store_true")
|
|
25
|
+
recovery = report.add_mutually_exclusive_group()
|
|
26
|
+
recovery.add_argument("--retry", action="store_true")
|
|
27
|
+
recovery.add_argument("--restart", action="store_true")
|
|
28
|
+
markdown = commands.add_parser(
|
|
29
|
+
"markdown", help="Render text reports as a Markdown table"
|
|
30
|
+
)
|
|
31
|
+
markdown.add_argument("--text", action="append", required=True)
|
|
32
|
+
search = commands.add_parser("search", help="Find notes in a local notebook")
|
|
33
|
+
preview = commands.add_parser("preview", help="Preview a local note")
|
|
34
|
+
move = commands.add_parser("move-plan", help="Preview a checked note move")
|
|
35
|
+
for command in (search, preview, move):
|
|
36
|
+
command.add_argument("notebook")
|
|
37
|
+
search.add_argument("query")
|
|
38
|
+
preview.add_argument("note")
|
|
39
|
+
move.add_argument("source")
|
|
40
|
+
move.add_argument("destination")
|
|
41
|
+
return parser
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _notebook_command(args):
|
|
45
|
+
from prettynb import Notebook
|
|
46
|
+
|
|
47
|
+
notebook = Notebook.open(args.notebook)
|
|
48
|
+
if args.command == "search":
|
|
49
|
+
return [asdict(hit) for hit in notebook.search(args.query)]
|
|
50
|
+
if args.command == "preview":
|
|
51
|
+
note = notebook.notes.get(args.note)
|
|
52
|
+
if note is None:
|
|
53
|
+
raise ValueError(f"Unknown note {args.note!r}")
|
|
54
|
+
return {"name": args.note, "markdown": note.current_md}
|
|
55
|
+
return notebook.move_note(args.source, args.destination, dry_run=True)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _dispatch(args):
|
|
59
|
+
if args.command in {"search", "preview", "move-plan"}:
|
|
60
|
+
return _notebook_command(args)
|
|
61
|
+
workbench = TextWorkbench()
|
|
62
|
+
if args.command == "inspect":
|
|
63
|
+
return {"schema": 1, "status": "inspected", "workflow": workbench.inspect()}
|
|
64
|
+
if args.command == "report":
|
|
65
|
+
return asyncio.run(
|
|
66
|
+
workbench.report(
|
|
67
|
+
args.text,
|
|
68
|
+
checkpoint=args.checkpoint,
|
|
69
|
+
resume=args.resume,
|
|
70
|
+
retry=args.retry,
|
|
71
|
+
restart=args.restart,
|
|
72
|
+
pace=args.pace,
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
if args.command == "markdown":
|
|
76
|
+
return {
|
|
77
|
+
"schema": 1,
|
|
78
|
+
"status": "rendered",
|
|
79
|
+
"format": "markdown",
|
|
80
|
+
"text": workbench.markdown(args.text),
|
|
81
|
+
}
|
|
82
|
+
return asyncio.run(workbench.review(args.text, checkpoint=args.checkpoint))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def main(argv=None) -> int:
|
|
86
|
+
args = _parser().parse_args(argv)
|
|
87
|
+
try:
|
|
88
|
+
result = _dispatch(args)
|
|
89
|
+
if result is not None:
|
|
90
|
+
sys.stdout.buffer.write(
|
|
91
|
+
(json.dumps(result, ensure_ascii=False) + "\n").encode("utf-8")
|
|
92
|
+
)
|
|
93
|
+
except (ValueError, KeyError, OSError, RuntimeError) as error:
|
|
94
|
+
print(str(error), file=sys.stderr)
|
|
95
|
+
return 1
|
|
96
|
+
return 0
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Port of the Peaches 0.1.0 text workflow to Function Sequence."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import TypedDict
|
|
6
|
+
|
|
7
|
+
from function_sequence import loads
|
|
8
|
+
from function_sequence.application import execute
|
|
9
|
+
from hidden_moves import Moves, MoveSet
|
|
10
|
+
from hidden_moves.adapters import CapabilityCatalog
|
|
11
|
+
from hidden_moves.adapters.function_sequence import CapabilityResolver
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TextReport(TypedDict):
|
|
15
|
+
text: str
|
|
16
|
+
words: int
|
|
17
|
+
characters: int
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def normalize(text: str) -> str:
|
|
21
|
+
"""Collapse Unicode whitespace and casefold text."""
|
|
22
|
+
return " ".join(text.split()).casefold()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def report(text: str) -> TextReport:
|
|
26
|
+
"""Report words and Unicode code points in the supplied text."""
|
|
27
|
+
return {"text": text, "words": len(text.split()), "characters": len(text)}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _workflow_document() -> dict:
|
|
31
|
+
return {
|
|
32
|
+
"schema": 1,
|
|
33
|
+
"name": "text-report",
|
|
34
|
+
"version": "1",
|
|
35
|
+
"steps": [
|
|
36
|
+
{
|
|
37
|
+
"id": "normalize",
|
|
38
|
+
"capability": "text.normalize",
|
|
39
|
+
"arguments": {"object": {"text": {"input": {"name": "text"}}}},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "report",
|
|
43
|
+
"capability": "text.report",
|
|
44
|
+
"arguments": {"object": {"text": {"ref": {"step": "normalize"}}}},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
"outputs": {"object": {"report": {"ref": {"step": "report"}}}},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class TextWorkbench:
|
|
52
|
+
"""Inspect, run and review the two explicitly selected text operations."""
|
|
53
|
+
|
|
54
|
+
def __init__(self, *, resolver_version: str = "prettynb-text-v1"):
|
|
55
|
+
self.resolver_version = resolver_version
|
|
56
|
+
self.workflow = loads(
|
|
57
|
+
json.dumps(_workflow_document()), source="prettynb-tui:text-report"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def inspect(self):
|
|
61
|
+
return self.workflow.inspect()
|
|
62
|
+
|
|
63
|
+
def catalog(self) -> CapabilityCatalog:
|
|
64
|
+
moves = Moves()
|
|
65
|
+
selected = MoveSet("text")
|
|
66
|
+
selected.learn(normalize)
|
|
67
|
+
selected.learn(report)
|
|
68
|
+
moves.registry.register_many(selected.moves())
|
|
69
|
+
return CapabilityCatalog(moves, ("text.normalize", "text.report"))
|
|
70
|
+
|
|
71
|
+
def _resolver(self) -> CapabilityResolver:
|
|
72
|
+
return CapabilityResolver(self.catalog(), version=self.resolver_version)
|
|
73
|
+
|
|
74
|
+
async def report(
|
|
75
|
+
self,
|
|
76
|
+
text: str,
|
|
77
|
+
*,
|
|
78
|
+
checkpoint: str | Path | None = None,
|
|
79
|
+
resume: bool = False,
|
|
80
|
+
retry: bool = False,
|
|
81
|
+
restart: bool = False,
|
|
82
|
+
pace: str = "auto",
|
|
83
|
+
control=None,
|
|
84
|
+
observer=None,
|
|
85
|
+
):
|
|
86
|
+
return await execute(
|
|
87
|
+
self.workflow,
|
|
88
|
+
self._resolver(),
|
|
89
|
+
resolver_version=self.resolver_version,
|
|
90
|
+
inputs={"text": text},
|
|
91
|
+
checkpoint=checkpoint,
|
|
92
|
+
resume=resume,
|
|
93
|
+
retry=retry,
|
|
94
|
+
restart=restart,
|
|
95
|
+
pace=pace,
|
|
96
|
+
control=control,
|
|
97
|
+
observer=observer,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def table(self, texts: list[str]):
|
|
101
|
+
from headless_spreadsheets import Table
|
|
102
|
+
|
|
103
|
+
if not isinstance(texts, list) or not 1 <= len(texts) <= 64:
|
|
104
|
+
raise ValueError("Select 1–64 text rows")
|
|
105
|
+
bound = self.workflow.bind(
|
|
106
|
+
self._resolver(), resolver_version=self.resolver_version
|
|
107
|
+
)
|
|
108
|
+
rows = [bound.run({"text": text}).outputs["report"] for text in texts]
|
|
109
|
+
return Table.from_records(rows, columns=("text", "words", "characters"))
|
|
110
|
+
|
|
111
|
+
def markdown(self, texts: list[str]) -> str:
|
|
112
|
+
return self.table(texts).to_document().to_markdown()
|
|
113
|
+
|
|
114
|
+
def terminal_model(self, text: str, *, checkpoint: str | Path):
|
|
115
|
+
from function_sequence.terminal import WorkflowTerminal
|
|
116
|
+
|
|
117
|
+
return WorkflowTerminal(
|
|
118
|
+
self.workflow,
|
|
119
|
+
self._resolver(),
|
|
120
|
+
resolver_version=self.resolver_version,
|
|
121
|
+
checkpoint=checkpoint,
|
|
122
|
+
inputs={"text": text},
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
async def review(self, text: str, *, checkpoint: str | Path, **terminal_options):
|
|
126
|
+
from function_sequence.terminal import run_terminal
|
|
127
|
+
|
|
128
|
+
return await run_terminal(
|
|
129
|
+
self.workflow,
|
|
130
|
+
self._resolver(),
|
|
131
|
+
resolver_version=self.resolver_version,
|
|
132
|
+
checkpoint=checkpoint,
|
|
133
|
+
inputs={"text": text},
|
|
134
|
+
**terminal_options,
|
|
135
|
+
)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
import tempfile
|
|
6
|
+
import time
|
|
7
|
+
import unittest
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@unittest.skipUnless(os.name == "posix", "Native POSIX review host")
|
|
12
|
+
class NativeReviewTests(unittest.TestCase):
|
|
13
|
+
def test_actual_terminal_selection_run_and_quit_restore_the_session(self):
|
|
14
|
+
import fcntl
|
|
15
|
+
import pty
|
|
16
|
+
import select
|
|
17
|
+
import struct
|
|
18
|
+
import termios
|
|
19
|
+
|
|
20
|
+
master, slave = pty.openpty()
|
|
21
|
+
fcntl.ioctl(slave, termios.TIOCSWINSZ, struct.pack("HHHH", 24, 80, 0, 0))
|
|
22
|
+
original = termios.tcgetattr(slave)
|
|
23
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
24
|
+
checkpoint = Path(directory) / "review.json"
|
|
25
|
+
process = subprocess.Popen(
|
|
26
|
+
[
|
|
27
|
+
sys.executable,
|
|
28
|
+
"-I",
|
|
29
|
+
"-m",
|
|
30
|
+
"prettynb_tui",
|
|
31
|
+
"review",
|
|
32
|
+
" Hello WORLD ",
|
|
33
|
+
"--checkpoint",
|
|
34
|
+
str(checkpoint),
|
|
35
|
+
],
|
|
36
|
+
stdin=slave,
|
|
37
|
+
stderr=slave,
|
|
38
|
+
stdout=subprocess.PIPE,
|
|
39
|
+
cwd=directory,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def drain():
|
|
43
|
+
if select.select([master], [], [], 0.02)[0]:
|
|
44
|
+
os.read(master, 65536)
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
deadline = time.monotonic() + 5
|
|
48
|
+
while (
|
|
49
|
+
termios.tcgetattr(slave)[3] & termios.ICANON
|
|
50
|
+
and process.poll() is None
|
|
51
|
+
and time.monotonic() < deadline
|
|
52
|
+
):
|
|
53
|
+
drain()
|
|
54
|
+
self.assertFalse(
|
|
55
|
+
termios.tcgetattr(slave)[3] & termios.ICANON,
|
|
56
|
+
"Native raw session did not start",
|
|
57
|
+
)
|
|
58
|
+
# Input editor → explicitly select both capabilities → actions → run.
|
|
59
|
+
os.write(master, b"\t \x1b[B \t\r")
|
|
60
|
+
completed = False
|
|
61
|
+
deadline = time.monotonic() + 5
|
|
62
|
+
while process.poll() is None and time.monotonic() < deadline:
|
|
63
|
+
drain()
|
|
64
|
+
if (
|
|
65
|
+
checkpoint.exists()
|
|
66
|
+
and json.loads(checkpoint.read_text())["status"] == "completed"
|
|
67
|
+
):
|
|
68
|
+
completed = True
|
|
69
|
+
break
|
|
70
|
+
self.assertTrue(completed, "Native keyboard execution did not complete")
|
|
71
|
+
os.write(master, b"q")
|
|
72
|
+
output, _ = process.communicate(timeout=5)
|
|
73
|
+
self.assertEqual(process.returncode, 0, output)
|
|
74
|
+
self.assertEqual(
|
|
75
|
+
json.loads(output)["outputs"],
|
|
76
|
+
{"report": {"text": "hello world", "words": 2, "characters": 11}},
|
|
77
|
+
)
|
|
78
|
+
restored = termios.tcgetattr(slave)
|
|
79
|
+
mask = termios.ICANON | termios.ECHO
|
|
80
|
+
self.assertEqual(restored[3] & mask, original[3] & mask)
|
|
81
|
+
finally:
|
|
82
|
+
if process.poll() is None:
|
|
83
|
+
process.kill()
|
|
84
|
+
process.communicate()
|
|
85
|
+
os.close(master)
|
|
86
|
+
os.close(slave)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
import unittest
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from prettynb import Notebook
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class NotebookCommandsTest(unittest.TestCase):
|
|
12
|
+
def test_search_preview_move_plan_are_read_only(self):
|
|
13
|
+
def invoke(*arguments):
|
|
14
|
+
result = subprocess.run(
|
|
15
|
+
[sys.executable, "-I", "-m", "prettynb_tui", *arguments],
|
|
16
|
+
capture_output=True,
|
|
17
|
+
check=True,
|
|
18
|
+
timeout=15,
|
|
19
|
+
)
|
|
20
|
+
return json.loads(result.stdout)
|
|
21
|
+
|
|
22
|
+
with tempfile.TemporaryDirectory() as temporary:
|
|
23
|
+
root = Path(temporary)
|
|
24
|
+
note = root / "sample.md"
|
|
25
|
+
note.write_text("# Sample\n\nA café notebook.\n", encoding="utf-8")
|
|
26
|
+
Notebook.open(root).initialize_identities()
|
|
27
|
+
before = {
|
|
28
|
+
path.relative_to(root): path.read_bytes()
|
|
29
|
+
for path in root.rglob("*")
|
|
30
|
+
if path.is_file()
|
|
31
|
+
}
|
|
32
|
+
matches = invoke("search", str(root), "café")
|
|
33
|
+
name = matches[0]["name"]
|
|
34
|
+
self.assertIn("café", invoke("preview", str(root), name)["markdown"])
|
|
35
|
+
plan = invoke("move-plan", str(root), "sample.md", "archive/sample.md")
|
|
36
|
+
self.assertTrue(plan["dry_run"])
|
|
37
|
+
after = {
|
|
38
|
+
path.relative_to(root): path.read_bytes()
|
|
39
|
+
for path in root.rglob("*")
|
|
40
|
+
if path.is_file()
|
|
41
|
+
}
|
|
42
|
+
self.assertEqual(after, before)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
import unittest
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from carets import KeyMsg
|
|
9
|
+
from carets.testing import TestProgram
|
|
10
|
+
from prettynb_tui import TextWorkbench
|
|
11
|
+
from prettynb_tui.workbench import normalize, report
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def run_reference(text):
|
|
15
|
+
return report(normalize(text))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ProfileTests(unittest.IsolatedAsyncioTestCase):
|
|
19
|
+
async def test_typed_table_markdown_and_terminal_reuse_report_contract(self):
|
|
20
|
+
workbench, text = TextWorkbench(), " Hello WORLD "
|
|
21
|
+
self.assertEqual(workbench.table([text]).to_records(), [run_reference(text)])
|
|
22
|
+
self.assertIn("<script>", workbench.markdown(["<script>"]))
|
|
23
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
24
|
+
model = workbench.terminal_model(
|
|
25
|
+
text, checkpoint=str(Path(directory) / "terminal.json")
|
|
26
|
+
)
|
|
27
|
+
test = TestProgram(model)
|
|
28
|
+
model.attach(test.program)
|
|
29
|
+
async with test:
|
|
30
|
+
await test.send(
|
|
31
|
+
KeyMsg("tab"),
|
|
32
|
+
KeyMsg(" "),
|
|
33
|
+
KeyMsg("down"),
|
|
34
|
+
KeyMsg(" "),
|
|
35
|
+
KeyMsg("tab"),
|
|
36
|
+
KeyMsg("enter"),
|
|
37
|
+
)
|
|
38
|
+
await test.wait_for(lambda: model.status == "completed")
|
|
39
|
+
self.assertEqual(
|
|
40
|
+
model.outcome["outputs"], {"report": run_reference(text)}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
async def test_installed_commands_pause_and_resume_in_separate_processes(self):
|
|
44
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
45
|
+
checkpoint = str(Path(directory) / "progress.json")
|
|
46
|
+
|
|
47
|
+
def command(*options):
|
|
48
|
+
result = subprocess.run(
|
|
49
|
+
[
|
|
50
|
+
sys.executable,
|
|
51
|
+
"-I",
|
|
52
|
+
"-m",
|
|
53
|
+
"prettynb_tui",
|
|
54
|
+
"report",
|
|
55
|
+
" Hello WORLD ",
|
|
56
|
+
"--checkpoint",
|
|
57
|
+
checkpoint,
|
|
58
|
+
*options,
|
|
59
|
+
],
|
|
60
|
+
cwd=directory,
|
|
61
|
+
capture_output=True,
|
|
62
|
+
check=False,
|
|
63
|
+
timeout=10,
|
|
64
|
+
)
|
|
65
|
+
self.assertEqual(result.returncode, 0, result.stderr)
|
|
66
|
+
return json.loads(result.stdout)
|
|
67
|
+
|
|
68
|
+
first = command("--pace", "function")
|
|
69
|
+
self.assertEqual(
|
|
70
|
+
(first["status"], first["completed"]), ("paused", ["normalize"])
|
|
71
|
+
)
|
|
72
|
+
resumed = command("--resume")
|
|
73
|
+
self.assertEqual(resumed["status"], "completed")
|
|
74
|
+
self.assertEqual(resumed["run_id"], first["run_id"])
|
|
75
|
+
self.assertEqual(
|
|
76
|
+
resumed["outputs"], {"report": run_reference(" Hello WORLD ")}
|
|
77
|
+
)
|