nctab 0.1.0__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.
- nctab-0.1.0/LICENSE +21 -0
- nctab-0.1.0/PKG-INFO +239 -0
- nctab-0.1.0/README.md +211 -0
- nctab-0.1.0/pyproject.toml +129 -0
- nctab-0.1.0/pyproject.toml.orig +103 -0
- nctab-0.1.0/src/nctab/__init__.py +3 -0
- nctab-0.1.0/src/nctab/app.py +604 -0
- nctab-0.1.0/src/nctab/check/__init__.py +13 -0
- nctab-0.1.0/src/nctab/check/model.py +65 -0
- nctab-0.1.0/src/nctab/check/rules.py +360 -0
- nctab-0.1.0/src/nctab/cli.py +1046 -0
- nctab-0.1.0/src/nctab/config.py +227 -0
- nctab-0.1.0/src/nctab/core/__init__.py +0 -0
- nctab-0.1.0/src/nctab/core/format.py +112 -0
- nctab-0.1.0/src/nctab/core/io.py +75 -0
- nctab-0.1.0/src/nctab/core/model.py +166 -0
- nctab-0.1.0/src/nctab/core/parse.py +293 -0
- nctab-0.1.0/src/nctab/core/state.py +218 -0
- nctab-0.1.0/src/nctab/diff/__init__.py +26 -0
- nctab-0.1.0/src/nctab/diff/compare.py +177 -0
- nctab-0.1.0/src/nctab/diff/normalize.py +91 -0
- nctab-0.1.0/src/nctab/dnc/__init__.py +0 -0
- nctab-0.1.0/src/nctab/errors.py +38 -0
- nctab-0.1.0/src/nctab/geom/__init__.py +0 -0
- nctab-0.1.0/src/nctab/geom/arc.py +100 -0
- nctab-0.1.0/src/nctab/geom/transform.py +87 -0
- nctab-0.1.0/src/nctab/nctab.tcss +157 -0
- nctab-0.1.0/src/nctab/ops/__init__.py +0 -0
- nctab-0.1.0/src/nctab/ops/addr_math.py +81 -0
- nctab-0.1.0/src/nctab/ops/base.py +167 -0
- nctab-0.1.0/src/nctab/ops/case.py +46 -0
- nctab-0.1.0/src/nctab/ops/feeds.py +89 -0
- nctab-0.1.0/src/nctab/ops/find.py +362 -0
- nctab-0.1.0/src/nctab/ops/mirror.py +170 -0
- nctab-0.1.0/src/nctab/ops/path.py +130 -0
- nctab-0.1.0/src/nctab/ops/renumber.py +112 -0
- nctab-0.1.0/src/nctab/ops/rotate.py +180 -0
- nctab-0.1.0/src/nctab/ops/scale.py +131 -0
- nctab-0.1.0/src/nctab/ops/shift.py +110 -0
- nctab-0.1.0/src/nctab/ops/stats.py +157 -0
- nctab-0.1.0/src/nctab/ops/strip.py +116 -0
- nctab-0.1.0/src/nctab/ops/tools.py +97 -0
- nctab-0.1.0/src/nctab/profiles/__init__.py +0 -0
- nctab-0.1.0/src/nctab/profiles/fanuc-mill.toml +99 -0
- nctab-0.1.0/src/nctab/profiles/fanuc-turn.toml +83 -0
- nctab-0.1.0/src/nctab/profiles/generic-iso.toml +59 -0
- nctab-0.1.0/src/nctab/profiles/haas-mill.toml +120 -0
- nctab-0.1.0/src/nctab/profiles/loader.py +119 -0
- nctab-0.1.0/src/nctab/profiles/siemens-iso.toml +83 -0
- nctab-0.1.0/src/nctab/snippets/__init__.py +17 -0
- nctab-0.1.0/src/nctab/snippets/common/program-footer.toml +11 -0
- nctab-0.1.0/src/nctab/snippets/common/program-header.toml +32 -0
- nctab-0.1.0/src/nctab/snippets/common/safe-retract.toml +14 -0
- nctab-0.1.0/src/nctab/snippets/common/tool-change.toml +29 -0
- nctab-0.1.0/src/nctab/snippets/fanuc-mill/drill-cycle.toml +27 -0
- nctab-0.1.0/src/nctab/snippets/fanuc-mill/peck-drill.toml +34 -0
- nctab-0.1.0/src/nctab/snippets/fanuc-turn/turn-header.toml +33 -0
- nctab-0.1.0/src/nctab/snippets/loader.py +212 -0
- nctab-0.1.0/src/nctab/tui/__init__.py +0 -0
- nctab-0.1.0/src/nctab/tui/dialogs.py +222 -0
- nctab-0.1.0/src/nctab/tui/editor.py +299 -0
- nctab-0.1.0/src/nctab/tui/explorer.py +85 -0
- nctab-0.1.0/src/nctab/tui/highlight.py +113 -0
- nctab-0.1.0/src/nctab/tui/inspector.py +134 -0
- nctab-0.1.0/src/nctab/tui/outline.py +116 -0
- nctab-0.1.0/src/nctab/tui/palette.py +74 -0
- nctab-0.1.0/src/nctab/tui/panels.py +129 -0
- nctab-0.1.0/src/nctab/tui/search.py +101 -0
- nctab-0.1.0/src/nctab/tui/search_dialog.py +407 -0
nctab-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 0ndrec
|
|
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.
|
nctab-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nctab
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Terminal NC/G-code editor and toolkit
|
|
5
|
+
Keywords: cnc,gcode,nc,tui,fanuc,iso
|
|
6
|
+
Author: 0ndrec
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Manufacturing
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering
|
|
16
|
+
Classifier: Topic :: Text Editors
|
|
17
|
+
Requires-Dist: textual>=8.2
|
|
18
|
+
Requires-Dist: cyclopts>=4.25
|
|
19
|
+
Requires-Dist: pydantic>=2.12
|
|
20
|
+
Requires-Dist: pydantic-settings>=2.12
|
|
21
|
+
Requires-Dist: platformdirs>=4.4
|
|
22
|
+
Requires-Dist: pyserial>=3.5 ; extra == 'dnc'
|
|
23
|
+
Requires-Python: >=3.13
|
|
24
|
+
Project-URL: Homepage, https://github.com/0ndrec/nctab
|
|
25
|
+
Project-URL: Issues, https://github.com/0ndrec/nctab/issues
|
|
26
|
+
Provides-Extra: dnc
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# nctab
|
|
30
|
+
|
|
31
|
+
Terminal NC/G-code editor and toolkit for CNC programmers who work over SSH, in tmux,
|
|
32
|
+
on a shop-floor PC without a Windows GUI.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
uvx nctab stats part.nc
|
|
36
|
+
uvx nctab shift part.nc --z -0.02 -o part_z.nc
|
|
37
|
+
uvx nctab diff --ignore-n old.nc new.nc
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Nothing is written without `--in-place` / `-i` or `--output` / `-o`: every transform
|
|
41
|
+
prints a diff and stops. Writes are atomic, and `--backup` keeps a `.bak` copy.
|
|
42
|
+
Numbers are `Decimal` throughout, and a line an operation does not touch comes back
|
|
43
|
+
byte for byte.
|
|
44
|
+
|
|
45
|
+
## Demo
|
|
46
|
+
|
|
47
|
+
<video src="content/nctab.mp4" controls muted width="100%"></video>
|
|
48
|
+
|
|
49
|
+
If the player does not load, [watch the demo video](content/nctab.mp4).
|
|
50
|
+
|
|
51
|
+
## Status
|
|
52
|
+
|
|
53
|
+
Stages 0 to 3 of [PLAN.md](PLAN.md) are done: the parser, machine profiles, all
|
|
54
|
+
code transforms, search and replace, validation, NC-aware diff, the TUI editor
|
|
55
|
+
and snippets. Packaging to PyPI and DNC sending are still to come.
|
|
56
|
+
|
|
57
|
+
The interface is English only.
|
|
58
|
+
|
|
59
|
+
## Editor
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
uvx nctab edit part.nc
|
|
63
|
+
uvx nctab part.nc # the same thing
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Three panes. On the left a panel with two tabs: the outline of tool sections,
|
|
67
|
+
and a file list showing the programs in your G-code folder. The editor is in the
|
|
68
|
+
middle, and on the right an inspector decodes the word under the cursor and
|
|
69
|
+
shows the modal state in effect on that line. Everything the inspector says
|
|
70
|
+
comes from the machine profile, so a custom profile teaches it new codes.
|
|
71
|
+
|
|
72
|
+
Opening a file from the list is refused while the buffer has unsaved changes:
|
|
73
|
+
save with `Ctrl+S`, or press `Ctrl+R` to discard them and open anyway.
|
|
74
|
+
|
|
75
|
+
The editor is always in insert mode, so no binding is a plain character: typing
|
|
76
|
+
`]` inserts `]`.
|
|
77
|
+
|
|
78
|
+
| Key | Action |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `Ctrl+F` | Find. Text, pattern, an address word, or a G/M code |
|
|
81
|
+
| `F3`, `Shift+F3` | Next and previous match, with a `3/17` counter |
|
|
82
|
+
| `Ctrl+G` | Go to a line number, or `N120` for a block |
|
|
83
|
+
| `F4`, `Shift+F4` | Next and previous tool change |
|
|
84
|
+
| `F5`, `Shift+F5` | Next and previous motion block |
|
|
85
|
+
| `Ctrl+B` then a letter | Set a bookmark |
|
|
86
|
+
| `Ctrl+J` then a letter | Jump to a bookmark |
|
|
87
|
+
| `Ctrl+H` | Find and replace, with a preview of every change |
|
|
88
|
+
| `Ctrl+N` | Renumber |
|
|
89
|
+
| `Ctrl+T` | Shift, scale, mirror or rotate |
|
|
90
|
+
| `F2` | Insert a snippet, with a live preview of the body |
|
|
91
|
+
| `F9` | Switch the left panel between the outline and the file list |
|
|
92
|
+
| `Ctrl+O` | Focus the left panel |
|
|
93
|
+
| `Ctrl+P` | Command palette |
|
|
94
|
+
| `Ctrl+S`, `Ctrl+Q` | Save, quit |
|
|
95
|
+
| `F1` | Key reminder in the status bar |
|
|
96
|
+
|
|
97
|
+
### Find and replace
|
|
98
|
+
|
|
99
|
+
Both keys open the same dialog, in find or replace mode. Pick how to search from
|
|
100
|
+
one dropdown: plain text, a regular expression, an address word, or a G or M
|
|
101
|
+
code.
|
|
102
|
+
|
|
103
|
+
The match count updates while you type, and every match is listed with its line
|
|
104
|
+
and block number, so an empty search or a pattern that catches too much is
|
|
105
|
+
obvious before you commit to it. Picking a row from the list jumps the editor
|
|
106
|
+
straight to that match. In the file itself every match is highlighted at once
|
|
107
|
+
and the current one picked out, so you can see the distribution at a glance.
|
|
108
|
+
|
|
109
|
+
In address mode there is no typing at all: one dropdown lists the addresses the
|
|
110
|
+
program uses with their counts, the other lists the values that address actually
|
|
111
|
+
takes, with the line each first appears on. No more guessing whether the file
|
|
112
|
+
says `F300` or `F300.`.
|
|
113
|
+
|
|
114
|
+
Replace shows what each match becomes before anything is written, computed by
|
|
115
|
+
the same code that performs the edit, so the preview cannot disagree with the
|
|
116
|
+
result. A match that would not actually change is labelled as such. Individual
|
|
117
|
+
rows can be switched off with `Space`, or in bulk with `All` and `None`, so
|
|
118
|
+
"every F except that one" needs no cleverness with the pattern.
|
|
119
|
+
|
|
120
|
+
## Commands
|
|
121
|
+
|
|
122
|
+
### Inspect
|
|
123
|
+
|
|
124
|
+
| Command | What it does |
|
|
125
|
+
|---|---|
|
|
126
|
+
| `nctab stats FILE` | Line and block counts, axis min/max, G/M histogram, tools, feeds, speeds, path lengths |
|
|
127
|
+
| `nctab tools FILE` | Each tool section: first line, block count, D/H offsets, speeds, feeds, name from the nearest comment |
|
|
128
|
+
| `nctab check FILE` | 21 validation rules; exit code 2 on an error, `--strict` also on a warning |
|
|
129
|
+
| `nctab profiles` | Available machine profiles, with the active one marked |
|
|
130
|
+
|
|
131
|
+
### Search
|
|
132
|
+
|
|
133
|
+
| Command | What it does |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `nctab find FILE "G41 D"` | Text search; `--regex` for a pattern, `--case` to match case |
|
|
136
|
+
| `nctab find FILE --addr F` | Every distinct F value with counts and where it occurs |
|
|
137
|
+
| `nctab find FILE --addr F --value 300` | The F300 words themselves; `--min`/`--max` for a range |
|
|
138
|
+
| `nctab find FILE --code G02` | Every G02 block, however it is zero-padded |
|
|
139
|
+
| `nctab replace FILE --addr F --value 300 --to 250` | Batch replace keeping the source number style |
|
|
140
|
+
| `nctab replace FILE --regex 'X(\d+)\.' --to 'X\1.0'` | Regex replace with back-references |
|
|
141
|
+
|
|
142
|
+
Comments are never touched unless you pass `--in-comments`.
|
|
143
|
+
|
|
144
|
+
### Transform
|
|
145
|
+
|
|
146
|
+
| Command | What it does |
|
|
147
|
+
|---|---|
|
|
148
|
+
| `nctab renumber FILE --start 10 --step 10` | Renumber N blocks; `--width 4` for `N0010`, `--strip` to remove them |
|
|
149
|
+
| `nctab strip FILE --n --comments --blank` | Remove block numbers, comments, blank lines, `/` marks or blocks, spaces |
|
|
150
|
+
| `nctab case FILE upper` | Upper- or lower-case the code, leaving comments alone |
|
|
151
|
+
| `nctab shift FILE --z -0.02` | Translate absolute coordinates |
|
|
152
|
+
| `nctab math FILE --addr Z --op add --value -0.013` | Arithmetic on every word of an address |
|
|
153
|
+
| `nctab feeds FILE --f-scale 0.9 --f-min 80` | Scale and clamp feeds and spindle speeds |
|
|
154
|
+
| `nctab scale FILE --factor 1.02 --about 0,0,0` | Scale linear axes about a point |
|
|
155
|
+
| `nctab mirror FILE --axis x` | Mirror an axis, swapping G02/G03 and G41/G42 |
|
|
156
|
+
| `nctab rotate FILE --deg 90 --cx 50 --cy 25` | Rotate in the G17 plane; multiples of 90° are exact |
|
|
157
|
+
|
|
158
|
+
Every transform takes `--range` / `-r` to limit the work: `10-200` for lines,
|
|
159
|
+
`N100-N500` for block numbers, `T12` for one tool's section.
|
|
160
|
+
|
|
161
|
+
### Snippets
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
nctab snippets
|
|
165
|
+
nctab snippets tool-change --set T=7 --set S=4500
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Snippets are TOML files with typed fields and a body. Built-ins cover the
|
|
169
|
+
program header and footer, tool change, safe retract and the drilling cycles;
|
|
170
|
+
drop your own in `~/.config/nctab/snippets/`, or in a `<profile-id>` folder
|
|
171
|
+
under it to limit them to one control. A float field writes `Z-10.` rather than
|
|
172
|
+
`Z-10`, because a missing decimal point is read as the least significant
|
|
173
|
+
increment on some controls.
|
|
174
|
+
|
|
175
|
+
### Compare
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
nctab diff old.nc new.nc --ignore-n --ignore-whitespace
|
|
179
|
+
nctab diff old.nc new.nc --normalize-all --side-by-side
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Exit code is 1 when the files differ, so it can gate a CI step.
|
|
183
|
+
|
|
184
|
+
## Machine profiles
|
|
185
|
+
|
|
186
|
+
`fanuc-mill`, `fanuc-turn`, `haas-mill`, `siemens-iso`, `generic-iso`. A profile
|
|
187
|
+
describes the dialect: comment syntax, axis letters, plane codes, the G and M code
|
|
188
|
+
dictionary, and the number format. Pick one with `--profile` / `-p`, or point it at
|
|
189
|
+
your own file: `-p ./my-control.toml`. User profiles also load from
|
|
190
|
+
`~/.config/nctab/profiles/`.
|
|
191
|
+
|
|
192
|
+
## Configuration
|
|
193
|
+
|
|
194
|
+
Layers, later ones winning: built-in defaults, `~/.config/nctab/config.toml`, the
|
|
195
|
+
nearest `.nctab.toml` at or above the working directory, `NCTAB_*` environment
|
|
196
|
+
variables, then CLI flags.
|
|
197
|
+
|
|
198
|
+
```toml
|
|
199
|
+
[editor]
|
|
200
|
+
backup = true
|
|
201
|
+
|
|
202
|
+
[defaults]
|
|
203
|
+
directory = "~/nc" # where the programs live
|
|
204
|
+
profile = "fanuc-mill"
|
|
205
|
+
digits = "preserve" # or a number of fractional digits
|
|
206
|
+
rounding = "HALF_UP"
|
|
207
|
+
arc_tolerance = 0.001
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`directory` is the folder of G-code programs. The editor's file list opens
|
|
211
|
+
there, and a bare file name the CLI cannot find in the working directory is
|
|
212
|
+
looked up there too, so `nctab stats OP20.nc` works from anywhere. A file that
|
|
213
|
+
does exist where you are standing still wins. Unset means the working
|
|
214
|
+
directory, so nothing changes until you set it. `NCTAB_DIR` overrides it for
|
|
215
|
+
one command.
|
|
216
|
+
|
|
217
|
+
A malformed config layer is reported as a warning and skipped, never fatal.
|
|
218
|
+
|
|
219
|
+
## JSON output
|
|
220
|
+
|
|
221
|
+
Every reporting command takes `--json` and emits a versioned schema, so `stats`,
|
|
222
|
+
`check`, `tools` and `diff` can drive a CI job.
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
uvx nctab check part.nc --json | jq '.diagnostics[] | select(.severity=="error")'
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Development
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
uv sync --all-extras
|
|
232
|
+
uv run pytest
|
|
233
|
+
uv run ruff check && uv run ruff format --check
|
|
234
|
+
uv run ty check src
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT
|
nctab-0.1.0/README.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# nctab
|
|
2
|
+
|
|
3
|
+
Terminal NC/G-code editor and toolkit for CNC programmers who work over SSH, in tmux,
|
|
4
|
+
on a shop-floor PC without a Windows GUI.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
uvx nctab stats part.nc
|
|
8
|
+
uvx nctab shift part.nc --z -0.02 -o part_z.nc
|
|
9
|
+
uvx nctab diff --ignore-n old.nc new.nc
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Nothing is written without `--in-place` / `-i` or `--output` / `-o`: every transform
|
|
13
|
+
prints a diff and stops. Writes are atomic, and `--backup` keeps a `.bak` copy.
|
|
14
|
+
Numbers are `Decimal` throughout, and a line an operation does not touch comes back
|
|
15
|
+
byte for byte.
|
|
16
|
+
|
|
17
|
+
## Demo
|
|
18
|
+
|
|
19
|
+
<video src="content/nctab.mp4" controls muted width="100%"></video>
|
|
20
|
+
|
|
21
|
+
If the player does not load, [watch the demo video](content/nctab.mp4).
|
|
22
|
+
|
|
23
|
+
## Status
|
|
24
|
+
|
|
25
|
+
Stages 0 to 3 of [PLAN.md](PLAN.md) are done: the parser, machine profiles, all
|
|
26
|
+
code transforms, search and replace, validation, NC-aware diff, the TUI editor
|
|
27
|
+
and snippets. Packaging to PyPI and DNC sending are still to come.
|
|
28
|
+
|
|
29
|
+
The interface is English only.
|
|
30
|
+
|
|
31
|
+
## Editor
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uvx nctab edit part.nc
|
|
35
|
+
uvx nctab part.nc # the same thing
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Three panes. On the left a panel with two tabs: the outline of tool sections,
|
|
39
|
+
and a file list showing the programs in your G-code folder. The editor is in the
|
|
40
|
+
middle, and on the right an inspector decodes the word under the cursor and
|
|
41
|
+
shows the modal state in effect on that line. Everything the inspector says
|
|
42
|
+
comes from the machine profile, so a custom profile teaches it new codes.
|
|
43
|
+
|
|
44
|
+
Opening a file from the list is refused while the buffer has unsaved changes:
|
|
45
|
+
save with `Ctrl+S`, or press `Ctrl+R` to discard them and open anyway.
|
|
46
|
+
|
|
47
|
+
The editor is always in insert mode, so no binding is a plain character: typing
|
|
48
|
+
`]` inserts `]`.
|
|
49
|
+
|
|
50
|
+
| Key | Action |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `Ctrl+F` | Find. Text, pattern, an address word, or a G/M code |
|
|
53
|
+
| `F3`, `Shift+F3` | Next and previous match, with a `3/17` counter |
|
|
54
|
+
| `Ctrl+G` | Go to a line number, or `N120` for a block |
|
|
55
|
+
| `F4`, `Shift+F4` | Next and previous tool change |
|
|
56
|
+
| `F5`, `Shift+F5` | Next and previous motion block |
|
|
57
|
+
| `Ctrl+B` then a letter | Set a bookmark |
|
|
58
|
+
| `Ctrl+J` then a letter | Jump to a bookmark |
|
|
59
|
+
| `Ctrl+H` | Find and replace, with a preview of every change |
|
|
60
|
+
| `Ctrl+N` | Renumber |
|
|
61
|
+
| `Ctrl+T` | Shift, scale, mirror or rotate |
|
|
62
|
+
| `F2` | Insert a snippet, with a live preview of the body |
|
|
63
|
+
| `F9` | Switch the left panel between the outline and the file list |
|
|
64
|
+
| `Ctrl+O` | Focus the left panel |
|
|
65
|
+
| `Ctrl+P` | Command palette |
|
|
66
|
+
| `Ctrl+S`, `Ctrl+Q` | Save, quit |
|
|
67
|
+
| `F1` | Key reminder in the status bar |
|
|
68
|
+
|
|
69
|
+
### Find and replace
|
|
70
|
+
|
|
71
|
+
Both keys open the same dialog, in find or replace mode. Pick how to search from
|
|
72
|
+
one dropdown: plain text, a regular expression, an address word, or a G or M
|
|
73
|
+
code.
|
|
74
|
+
|
|
75
|
+
The match count updates while you type, and every match is listed with its line
|
|
76
|
+
and block number, so an empty search or a pattern that catches too much is
|
|
77
|
+
obvious before you commit to it. Picking a row from the list jumps the editor
|
|
78
|
+
straight to that match. In the file itself every match is highlighted at once
|
|
79
|
+
and the current one picked out, so you can see the distribution at a glance.
|
|
80
|
+
|
|
81
|
+
In address mode there is no typing at all: one dropdown lists the addresses the
|
|
82
|
+
program uses with their counts, the other lists the values that address actually
|
|
83
|
+
takes, with the line each first appears on. No more guessing whether the file
|
|
84
|
+
says `F300` or `F300.`.
|
|
85
|
+
|
|
86
|
+
Replace shows what each match becomes before anything is written, computed by
|
|
87
|
+
the same code that performs the edit, so the preview cannot disagree with the
|
|
88
|
+
result. A match that would not actually change is labelled as such. Individual
|
|
89
|
+
rows can be switched off with `Space`, or in bulk with `All` and `None`, so
|
|
90
|
+
"every F except that one" needs no cleverness with the pattern.
|
|
91
|
+
|
|
92
|
+
## Commands
|
|
93
|
+
|
|
94
|
+
### Inspect
|
|
95
|
+
|
|
96
|
+
| Command | What it does |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `nctab stats FILE` | Line and block counts, axis min/max, G/M histogram, tools, feeds, speeds, path lengths |
|
|
99
|
+
| `nctab tools FILE` | Each tool section: first line, block count, D/H offsets, speeds, feeds, name from the nearest comment |
|
|
100
|
+
| `nctab check FILE` | 21 validation rules; exit code 2 on an error, `--strict` also on a warning |
|
|
101
|
+
| `nctab profiles` | Available machine profiles, with the active one marked |
|
|
102
|
+
|
|
103
|
+
### Search
|
|
104
|
+
|
|
105
|
+
| Command | What it does |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `nctab find FILE "G41 D"` | Text search; `--regex` for a pattern, `--case` to match case |
|
|
108
|
+
| `nctab find FILE --addr F` | Every distinct F value with counts and where it occurs |
|
|
109
|
+
| `nctab find FILE --addr F --value 300` | The F300 words themselves; `--min`/`--max` for a range |
|
|
110
|
+
| `nctab find FILE --code G02` | Every G02 block, however it is zero-padded |
|
|
111
|
+
| `nctab replace FILE --addr F --value 300 --to 250` | Batch replace keeping the source number style |
|
|
112
|
+
| `nctab replace FILE --regex 'X(\d+)\.' --to 'X\1.0'` | Regex replace with back-references |
|
|
113
|
+
|
|
114
|
+
Comments are never touched unless you pass `--in-comments`.
|
|
115
|
+
|
|
116
|
+
### Transform
|
|
117
|
+
|
|
118
|
+
| Command | What it does |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `nctab renumber FILE --start 10 --step 10` | Renumber N blocks; `--width 4` for `N0010`, `--strip` to remove them |
|
|
121
|
+
| `nctab strip FILE --n --comments --blank` | Remove block numbers, comments, blank lines, `/` marks or blocks, spaces |
|
|
122
|
+
| `nctab case FILE upper` | Upper- or lower-case the code, leaving comments alone |
|
|
123
|
+
| `nctab shift FILE --z -0.02` | Translate absolute coordinates |
|
|
124
|
+
| `nctab math FILE --addr Z --op add --value -0.013` | Arithmetic on every word of an address |
|
|
125
|
+
| `nctab feeds FILE --f-scale 0.9 --f-min 80` | Scale and clamp feeds and spindle speeds |
|
|
126
|
+
| `nctab scale FILE --factor 1.02 --about 0,0,0` | Scale linear axes about a point |
|
|
127
|
+
| `nctab mirror FILE --axis x` | Mirror an axis, swapping G02/G03 and G41/G42 |
|
|
128
|
+
| `nctab rotate FILE --deg 90 --cx 50 --cy 25` | Rotate in the G17 plane; multiples of 90° are exact |
|
|
129
|
+
|
|
130
|
+
Every transform takes `--range` / `-r` to limit the work: `10-200` for lines,
|
|
131
|
+
`N100-N500` for block numbers, `T12` for one tool's section.
|
|
132
|
+
|
|
133
|
+
### Snippets
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
nctab snippets
|
|
137
|
+
nctab snippets tool-change --set T=7 --set S=4500
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Snippets are TOML files with typed fields and a body. Built-ins cover the
|
|
141
|
+
program header and footer, tool change, safe retract and the drilling cycles;
|
|
142
|
+
drop your own in `~/.config/nctab/snippets/`, or in a `<profile-id>` folder
|
|
143
|
+
under it to limit them to one control. A float field writes `Z-10.` rather than
|
|
144
|
+
`Z-10`, because a missing decimal point is read as the least significant
|
|
145
|
+
increment on some controls.
|
|
146
|
+
|
|
147
|
+
### Compare
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
nctab diff old.nc new.nc --ignore-n --ignore-whitespace
|
|
151
|
+
nctab diff old.nc new.nc --normalize-all --side-by-side
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Exit code is 1 when the files differ, so it can gate a CI step.
|
|
155
|
+
|
|
156
|
+
## Machine profiles
|
|
157
|
+
|
|
158
|
+
`fanuc-mill`, `fanuc-turn`, `haas-mill`, `siemens-iso`, `generic-iso`. A profile
|
|
159
|
+
describes the dialect: comment syntax, axis letters, plane codes, the G and M code
|
|
160
|
+
dictionary, and the number format. Pick one with `--profile` / `-p`, or point it at
|
|
161
|
+
your own file: `-p ./my-control.toml`. User profiles also load from
|
|
162
|
+
`~/.config/nctab/profiles/`.
|
|
163
|
+
|
|
164
|
+
## Configuration
|
|
165
|
+
|
|
166
|
+
Layers, later ones winning: built-in defaults, `~/.config/nctab/config.toml`, the
|
|
167
|
+
nearest `.nctab.toml` at or above the working directory, `NCTAB_*` environment
|
|
168
|
+
variables, then CLI flags.
|
|
169
|
+
|
|
170
|
+
```toml
|
|
171
|
+
[editor]
|
|
172
|
+
backup = true
|
|
173
|
+
|
|
174
|
+
[defaults]
|
|
175
|
+
directory = "~/nc" # where the programs live
|
|
176
|
+
profile = "fanuc-mill"
|
|
177
|
+
digits = "preserve" # or a number of fractional digits
|
|
178
|
+
rounding = "HALF_UP"
|
|
179
|
+
arc_tolerance = 0.001
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
`directory` is the folder of G-code programs. The editor's file list opens
|
|
183
|
+
there, and a bare file name the CLI cannot find in the working directory is
|
|
184
|
+
looked up there too, so `nctab stats OP20.nc` works from anywhere. A file that
|
|
185
|
+
does exist where you are standing still wins. Unset means the working
|
|
186
|
+
directory, so nothing changes until you set it. `NCTAB_DIR` overrides it for
|
|
187
|
+
one command.
|
|
188
|
+
|
|
189
|
+
A malformed config layer is reported as a warning and skipped, never fatal.
|
|
190
|
+
|
|
191
|
+
## JSON output
|
|
192
|
+
|
|
193
|
+
Every reporting command takes `--json` and emits a versioned schema, so `stats`,
|
|
194
|
+
`check`, `tools` and `diff` can drive a CI job.
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
uvx nctab check part.nc --json | jq '.diagnostics[] | select(.severity=="error")'
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Development
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
uv sync --all-extras
|
|
204
|
+
uv run pytest
|
|
205
|
+
uv run ruff check && uv run ruff format --check
|
|
206
|
+
uv run ty check src
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
MIT
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "nctab"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Terminal NC/G-code editor and toolkit"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
keywords = [
|
|
10
|
+
"cnc",
|
|
11
|
+
"gcode",
|
|
12
|
+
"nc",
|
|
13
|
+
"tui",
|
|
14
|
+
"fanuc",
|
|
15
|
+
"iso",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Environment :: Console",
|
|
20
|
+
"Intended Audience :: Manufacturing",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: Scientific/Engineering",
|
|
25
|
+
"Topic :: Text Editors",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"textual>=8.2",
|
|
29
|
+
"cyclopts>=4.25",
|
|
30
|
+
"pydantic>=2.12",
|
|
31
|
+
"pydantic-settings>=2.12",
|
|
32
|
+
"platformdirs>=4.4",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[[project.authors]]
|
|
36
|
+
name = "0ndrec"
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
dnc = ["pyserial>=3.5"]
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
nctab = "nctab.cli:main"
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/0ndrec/nctab"
|
|
46
|
+
Issues = "https://github.com/0ndrec/nctab/issues"
|
|
47
|
+
|
|
48
|
+
[build-system]
|
|
49
|
+
requires = ["uv_build>=0.12,<0.13"]
|
|
50
|
+
build-backend = "uv_build"
|
|
51
|
+
|
|
52
|
+
[tool.uv]
|
|
53
|
+
package = true
|
|
54
|
+
|
|
55
|
+
[tool.ruff]
|
|
56
|
+
target-version = "py313"
|
|
57
|
+
line-length = 100
|
|
58
|
+
src = [
|
|
59
|
+
"src",
|
|
60
|
+
"tests",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
[tool.ruff.lint]
|
|
64
|
+
select = [
|
|
65
|
+
"E",
|
|
66
|
+
"F",
|
|
67
|
+
"W",
|
|
68
|
+
"I",
|
|
69
|
+
"UP",
|
|
70
|
+
"B",
|
|
71
|
+
"SIM",
|
|
72
|
+
"RUF",
|
|
73
|
+
"TID",
|
|
74
|
+
"PL",
|
|
75
|
+
]
|
|
76
|
+
ignore = [
|
|
77
|
+
"PLR0913",
|
|
78
|
+
"PLR0911",
|
|
79
|
+
"PLR0912",
|
|
80
|
+
"PLR0915",
|
|
81
|
+
"PLR0917",
|
|
82
|
+
"PLR2004",
|
|
83
|
+
"RUF001",
|
|
84
|
+
"RUF002",
|
|
85
|
+
"RUF003",
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint.per-file-ignores]
|
|
89
|
+
"tests/**" = ["PLR"]
|
|
90
|
+
"src/nctab/app.py" = [
|
|
91
|
+
"RUF012",
|
|
92
|
+
"PLC0415",
|
|
93
|
+
]
|
|
94
|
+
"src/nctab/tui/*.py" = [
|
|
95
|
+
"RUF012",
|
|
96
|
+
"PLC0415",
|
|
97
|
+
]
|
|
98
|
+
"src/nctab/cli.py" = ["PLC0415"]
|
|
99
|
+
|
|
100
|
+
[tool.ruff.format]
|
|
101
|
+
quote-style = "double"
|
|
102
|
+
|
|
103
|
+
[tool.pytest.ini_options]
|
|
104
|
+
testpaths = ["tests"]
|
|
105
|
+
addopts = "-q --strict-markers"
|
|
106
|
+
asyncio_mode = "auto"
|
|
107
|
+
markers = ["slow: long-running tests"]
|
|
108
|
+
|
|
109
|
+
[tool.coverage.run]
|
|
110
|
+
source = ["nctab"]
|
|
111
|
+
branch = true
|
|
112
|
+
|
|
113
|
+
[tool.coverage.report]
|
|
114
|
+
show_missing = true
|
|
115
|
+
exclude_lines = [
|
|
116
|
+
"pragma: no cover",
|
|
117
|
+
"if TYPE_CHECKING:",
|
|
118
|
+
"raise NotImplementedError",
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
[dependency-groups]
|
|
122
|
+
dev = [
|
|
123
|
+
"pytest>=8.4",
|
|
124
|
+
"pytest-cov>=6.0",
|
|
125
|
+
"hypothesis>=6.100",
|
|
126
|
+
"ruff>=0.13",
|
|
127
|
+
"ty>=0.0.1a1",
|
|
128
|
+
"pytest-asyncio>=1.4.0",
|
|
129
|
+
]
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "nctab"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Terminal NC/G-code editor and toolkit"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "0ndrec" }]
|
|
10
|
+
keywords = ["cnc", "gcode", "nc", "tui", "fanuc", "iso"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Environment :: Console",
|
|
14
|
+
"Intended Audience :: Manufacturing",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Topic :: Scientific/Engineering",
|
|
19
|
+
"Topic :: Text Editors",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"textual>=8.2",
|
|
23
|
+
"cyclopts>=4.25",
|
|
24
|
+
"pydantic>=2.12",
|
|
25
|
+
"pydantic-settings>=2.12",
|
|
26
|
+
"platformdirs>=4.4",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dnc = ["pyserial>=3.5"]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
nctab = "nctab.cli:main"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/0ndrec/nctab"
|
|
37
|
+
Issues = "https://github.com/0ndrec/nctab/issues"
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["uv_build>=0.12,<0.13"]
|
|
41
|
+
build-backend = "uv_build"
|
|
42
|
+
|
|
43
|
+
[tool.uv]
|
|
44
|
+
package = true
|
|
45
|
+
|
|
46
|
+
[dependency-groups]
|
|
47
|
+
dev = [
|
|
48
|
+
"pytest>=8.4",
|
|
49
|
+
"pytest-cov>=6.0",
|
|
50
|
+
"hypothesis>=6.100",
|
|
51
|
+
"ruff>=0.13",
|
|
52
|
+
"ty>=0.0.1a1",
|
|
53
|
+
"pytest-asyncio>=1.4.0",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
target-version = "py313"
|
|
58
|
+
line-length = 100
|
|
59
|
+
src = ["src", "tests"]
|
|
60
|
+
|
|
61
|
+
[tool.ruff.lint]
|
|
62
|
+
select = [
|
|
63
|
+
"E", "F", "W", # pycodestyle / pyflakes
|
|
64
|
+
"I", # isort
|
|
65
|
+
"UP", # pyupgrade
|
|
66
|
+
"B", # bugbear
|
|
67
|
+
"SIM", # simplify
|
|
68
|
+
"RUF", # ruff-specific
|
|
69
|
+
"TID", # tidy imports (layer boundaries)
|
|
70
|
+
"PL", # pylint subset
|
|
71
|
+
]
|
|
72
|
+
ignore = [
|
|
73
|
+
"PLR0913", # too many arguments — CLI commands legitimately have many flags
|
|
74
|
+
"PLR0911", "PLR0912", "PLR0915", # too many returns/branches/statements — tokenisers are branchy
|
|
75
|
+
"PLR0917", # too many positional args — geometry helpers take coordinate tuples
|
|
76
|
+
"PLR2004", # magic values — G-code is full of them
|
|
77
|
+
"RUF001", "RUF002", "RUF003", # cyrillic in strings/comments/docstrings is intended
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
[tool.ruff.lint.per-file-ignores]
|
|
81
|
+
"tests/**" = ["PLR"]
|
|
82
|
+
# Textual declares BINDINGS/COMMANDS as plain class lists; deferred imports keep
|
|
83
|
+
# the CLI fast and avoid import cycles between the app and its widgets.
|
|
84
|
+
"src/nctab/app.py" = ["RUF012", "PLC0415"]
|
|
85
|
+
"src/nctab/tui/*.py" = ["RUF012", "PLC0415"]
|
|
86
|
+
"src/nctab/cli.py" = ["PLC0415"]
|
|
87
|
+
|
|
88
|
+
[tool.ruff.format]
|
|
89
|
+
quote-style = "double"
|
|
90
|
+
|
|
91
|
+
[tool.pytest.ini_options]
|
|
92
|
+
testpaths = ["tests"]
|
|
93
|
+
addopts = "-q --strict-markers"
|
|
94
|
+
asyncio_mode = "auto"
|
|
95
|
+
markers = ["slow: long-running tests"]
|
|
96
|
+
|
|
97
|
+
[tool.coverage.run]
|
|
98
|
+
source = ["nctab"]
|
|
99
|
+
branch = true
|
|
100
|
+
|
|
101
|
+
[tool.coverage.report]
|
|
102
|
+
show_missing = true
|
|
103
|
+
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:", "raise NotImplementedError"]
|