ghosttpy 0.1.1__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.
- ghosttpy-0.1.1/.github/workflows/ci.yml +25 -0
- ghosttpy-0.1.1/.github/workflows/publish.yml +51 -0
- ghosttpy-0.1.1/.gitignore +207 -0
- ghosttpy-0.1.1/.pre-commit-config.yaml +7 -0
- ghosttpy-0.1.1/.python-version +1 -0
- ghosttpy-0.1.1/LICENSE +21 -0
- ghosttpy-0.1.1/PKG-INFO +245 -0
- ghosttpy-0.1.1/README.md +226 -0
- ghosttpy-0.1.1/pyproject.toml +39 -0
- ghosttpy-0.1.1/src/ghosttpy.py +746 -0
- ghosttpy-0.1.1/tests/conftest.py +34 -0
- ghosttpy-0.1.1/tests/test_integration.py +206 -0
- ghosttpy-0.1.1/tests/test_scripting.py +577 -0
- ghosttpy-0.1.1/tests/test_types.py +365 -0
- ghosttpy-0.1.1/uv.lock +79 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
lint:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: astral-sh/setup-uv@v5
|
|
17
|
+
- run: uvx ruff check src/ tests/
|
|
18
|
+
- run: uvx ruff format --check src/ tests/
|
|
19
|
+
|
|
20
|
+
test:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
- uses: astral-sh/setup-uv@v5
|
|
25
|
+
- run: uv run pytest -m "not integration" -v
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: astral-sh/setup-uv@v5
|
|
16
|
+
|
|
17
|
+
- name: Verify version matches tag
|
|
18
|
+
run: |
|
|
19
|
+
TAG=${GITHUB_REF#refs/tags/v}
|
|
20
|
+
PKG_VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
|
|
21
|
+
if [ "$TAG" != "$PKG_VERSION" ]; then
|
|
22
|
+
echo "::error::Tag v$TAG does not match package version $PKG_VERSION"
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
- run: uv build
|
|
27
|
+
|
|
28
|
+
- uses: actions/upload-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: dist
|
|
31
|
+
path: dist/
|
|
32
|
+
|
|
33
|
+
publish:
|
|
34
|
+
needs: build
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
environment: pypi
|
|
37
|
+
permissions:
|
|
38
|
+
id-token: write
|
|
39
|
+
contents: read
|
|
40
|
+
attestations: write
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/download-artifact@v4
|
|
43
|
+
with:
|
|
44
|
+
name: dist
|
|
45
|
+
path: dist/
|
|
46
|
+
|
|
47
|
+
- uses: actions/attest-build-provenance@v2
|
|
48
|
+
with:
|
|
49
|
+
subject-path: "dist/*"
|
|
50
|
+
|
|
51
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
ghosttpy-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dylan Modesitt
|
|
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.
|
ghosttpy-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ghosttpy
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A Python library for scripting Ghostty
|
|
5
|
+
Project-URL: Homepage, https://github.com/DylanModesitt/ghosttpy
|
|
6
|
+
Project-URL: Repository, https://github.com/DylanModesitt/ghosttpy
|
|
7
|
+
Project-URL: Issues, https://github.com/DylanModesitt/ghosttpy/issues
|
|
8
|
+
Author-email: Dylan Modesitt <dylanmodesitt@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# ghosttpy
|
|
21
|
+
|
|
22
|
+
A Python interface for scripting [Ghostty](https://ghostty.org) on macOS via AppleScript.
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
- macOS
|
|
27
|
+
- Python >= 3.13
|
|
28
|
+
- [Ghostty](https://ghostty.org) >= 1.3.0 (when AppleScript support was introduced)
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
pip install ghosttpy
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
uv add ghosttpy
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from ghosttpy import Ghostty
|
|
46
|
+
|
|
47
|
+
g = Ghostty()
|
|
48
|
+
w = g.new_window(working_directory="/tmp")
|
|
49
|
+
term = w.selected_tab.focused_terminal
|
|
50
|
+
term.input("echo hello\n")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Accessing `w.name` or `term.working_directory` queries Ghostty to read the current state.
|
|
54
|
+
|
|
55
|
+
## Object model
|
|
56
|
+
|
|
57
|
+
Ghostty's scripting hierarchy is `Ghostty` > `Window` > `Tab` > `Terminal`. Each object has a stable `id` and can be compared or used in sets.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
g = Ghostty()
|
|
61
|
+
|
|
62
|
+
g.windows # all open windows
|
|
63
|
+
g.front_window # the frontmost window
|
|
64
|
+
g.name # "Ghostty"
|
|
65
|
+
g.version # e.g. "1.3.1"
|
|
66
|
+
g.frontmost # True if Ghostty is the active app
|
|
67
|
+
g.is_running # True if the Ghostty process is running
|
|
68
|
+
|
|
69
|
+
w = g.front_window
|
|
70
|
+
w.tabs # tabs in this window
|
|
71
|
+
w.terminals # all terminals across all tabs
|
|
72
|
+
w.selected_tab # the active tab
|
|
73
|
+
|
|
74
|
+
tab = w.selected_tab
|
|
75
|
+
tab.index # 1-based position in the tab bar
|
|
76
|
+
tab.selected # True if this tab is active
|
|
77
|
+
tab.focused_terminal
|
|
78
|
+
tab.terminals # terminals (split panes) in this tab
|
|
79
|
+
|
|
80
|
+
term = tab.focused_terminal
|
|
81
|
+
term.name
|
|
82
|
+
term.working_directory
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Creating windows, tabs, and splits
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
w = g.new_window()
|
|
89
|
+
tab = w.new_tab()
|
|
90
|
+
right = term.split("right") # returns the new Terminal
|
|
91
|
+
below = term.split("down")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Split directions are `"right"`, `"left"`, `"down"`, and `"up"` (or use the `SplitDirection` enum).
|
|
95
|
+
|
|
96
|
+
Close any object with `.close()`. Bring a window to the front with `w.activate()`, select a tab with `tab.select()`, or focus a terminal with `term.focus()`.
|
|
97
|
+
|
|
98
|
+
## Configuration
|
|
99
|
+
|
|
100
|
+
Windows, tabs, and splits accept keyword arguments to configure the terminal surface:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
w = g.new_window(font_size=14.0, working_directory="/tmp")
|
|
104
|
+
tab = w.new_tab(command="/bin/bash", environment={"EDITOR": "vim"})
|
|
105
|
+
new_term = term.split("right", initial_input="ls\n", wait_after_command=True)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Available options: `font_size`, `working_directory`, `command`, `initial_input`, `wait_after_command`, `environment`.
|
|
109
|
+
|
|
110
|
+
To reuse the same configuration across multiple calls, pass a `Surface` object:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from ghosttpy import Surface
|
|
114
|
+
|
|
115
|
+
cfg = Surface(font_size=14.0, working_directory="/tmp")
|
|
116
|
+
w1 = g.new_window(config=cfg)
|
|
117
|
+
w2 = g.new_window(config=cfg)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Terminal input
|
|
121
|
+
|
|
122
|
+
`input()` sends text as if pasted. `send_key()` sends individual key events.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
term.input("ls -la\n")
|
|
126
|
+
term.send_key("c", modifiers="control")
|
|
127
|
+
term.send_key("enter")
|
|
128
|
+
term.send_key("a", modifiers=["control", "shift"], action="release")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
`perform()` executes a [Ghostty action](https://ghostty.org/docs/config/keybind/reference) string and returns whether it succeeded:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
term.perform("copy_to_clipboard")
|
|
135
|
+
term.perform("reset")
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Mouse events are also available:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
term.send_mouse_position(x=100.0, y=200.0)
|
|
142
|
+
term.send_mouse_button("left button")
|
|
143
|
+
term.send_mouse_scroll(x=0, y=-3.0, precision=True)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Window management
|
|
147
|
+
|
|
148
|
+
Read or set a window's geometry:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from ghosttpy import Bounds, Point, Size
|
|
152
|
+
|
|
153
|
+
w.bounds # Bounds(left, top, right, bottom)
|
|
154
|
+
w.bounds = Bounds(0, 0, 960, 540)
|
|
155
|
+
|
|
156
|
+
w.position # Point(x, y)
|
|
157
|
+
w.size # Size(width, height)
|
|
158
|
+
|
|
159
|
+
w.move_to(100, 100)
|
|
160
|
+
w.resize_to(800, 600)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Tiling
|
|
164
|
+
|
|
165
|
+
Tile a window into a predefined screen region with `ScreenRegion`:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from ghosttpy import ScreenRegion
|
|
169
|
+
|
|
170
|
+
w.tile(ScreenRegion.left_half)
|
|
171
|
+
w.tile(ScreenRegion.top_right, gap=10)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Available regions:
|
|
175
|
+
|
|
176
|
+
| Halves | Quarters | Thirds | Fourths | Sixths |
|
|
177
|
+
|--------|----------|--------|---------|--------|
|
|
178
|
+
| `left_half` | `top_left` | `left_third` | `first_fourth` | `first_sixth` |
|
|
179
|
+
| `right_half` | `top_right` | `center_third` | `second_fourth` | `second_sixth` |
|
|
180
|
+
| `top_half` | `bottom_left` | `right_third` | `third_fourth` | `third_sixth` |
|
|
181
|
+
| `bottom_half` | `bottom_right` | `left_two_thirds` | `last_fourth` | `fourth_sixth` |
|
|
182
|
+
| | | `right_two_thirds` | `left_three_fourths` | `fifth_sixth` |
|
|
183
|
+
| | | | `right_three_fourths` | `last_sixth` |
|
|
184
|
+
|
|
185
|
+
There is also `full`, which is equivalent to `maximize()`.
|
|
186
|
+
|
|
187
|
+
### Maximize, center, and grid
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
w.maximize()
|
|
191
|
+
w.center()
|
|
192
|
+
|
|
193
|
+
# Tile all windows in an auto-sized grid
|
|
194
|
+
g.tile_windows()
|
|
195
|
+
|
|
196
|
+
# Tile specific windows in a 3-column grid with gaps
|
|
197
|
+
g.tile_windows([w1, w2, w3], columns=3, gap=10)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
All layout methods accept an optional `screen` parameter. When omitted, they use the main display.
|
|
201
|
+
|
|
202
|
+
## Screen geometry
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
scr = g.main_screen() # Screen for the primary display
|
|
206
|
+
scr.origin # Point -- top-left corner of usable area
|
|
207
|
+
scr.size # Size -- usable width and height (excludes menu bar and Dock)
|
|
208
|
+
scr.bounds # Bounds -- computed from origin and size
|
|
209
|
+
|
|
210
|
+
all_screens = g.screens() # list[Screen] for every display
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Raw AppleScript
|
|
214
|
+
|
|
215
|
+
For anything the library doesn't wrap, two escape hatches are available:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
# Runs inside `tell application "Ghostty" ... end tell`
|
|
219
|
+
g.tell('get name of front window')
|
|
220
|
+
|
|
221
|
+
# Runs raw AppleScript with no wrapping
|
|
222
|
+
g.run('tell application "Finder" to get name of front window')
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Error handling
|
|
226
|
+
|
|
227
|
+
Failed AppleScript calls raise `GhosttyError`, which includes the error message and an optional numeric `code`:
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
from ghosttpy import GhosttyError
|
|
231
|
+
|
|
232
|
+
try:
|
|
233
|
+
term.perform("nonexistent_action")
|
|
234
|
+
except GhosttyError as e:
|
|
235
|
+
print(e, e.code)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Enums
|
|
239
|
+
|
|
240
|
+
String arguments like `"right"`, `"press"`, and `"left button"` are accepted everywhere, but typed enum alternatives are available if you prefer:
|
|
241
|
+
|
|
242
|
+
- `SplitDirection` -- `right`, `left`, `down`, `up`
|
|
243
|
+
- `InputAction` -- `press`, `release`
|
|
244
|
+
- `MouseButton` -- `left`, `right`, `middle`
|
|
245
|
+
- `ScrollMomentum` -- `none`, `began`, `changed`, `ended`, `cancelled`, `may_begin`, `stationary`
|