tmcode 0.2.0__tar.gz → 0.3.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.
Files changed (45) hide show
  1. tmcode-0.3.1/PKG-INFO +158 -0
  2. tmcode-0.3.1/README.md +131 -0
  3. {tmcode-0.2.0 → tmcode-0.3.1}/pyproject.toml +2 -2
  4. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/__init__.py +1 -1
  5. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/app.py +133 -6
  6. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/cli.py +13 -3
  7. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/commands.py +1 -1
  8. tmcode-0.3.1/src/termcode/highlighting.py +187 -0
  9. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/modals.py +40 -0
  10. tmcode-0.3.1/src/termcode/pairs.py +100 -0
  11. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/runner.py +284 -5
  12. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/styles.tcss +8 -0
  13. tmcode-0.3.1/src/termcode/update.py +235 -0
  14. tmcode-0.3.1/src/tmcode.egg-info/PKG-INFO +158 -0
  15. {tmcode-0.2.0 → tmcode-0.3.1}/src/tmcode.egg-info/SOURCES.txt +5 -0
  16. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_app.py +96 -0
  17. tmcode-0.3.1/tests/test_pairs.py +81 -0
  18. tmcode-0.3.1/tests/test_pygments_fallback.py +43 -0
  19. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_runner.py +106 -1
  20. tmcode-0.3.1/tests/test_update.py +96 -0
  21. tmcode-0.2.0/PKG-INFO +0 -128
  22. tmcode-0.2.0/README.md +0 -101
  23. tmcode-0.2.0/src/termcode/highlighting.py +0 -61
  24. tmcode-0.2.0/src/tmcode.egg-info/PKG-INFO +0 -128
  25. {tmcode-0.2.0 → tmcode-0.3.1}/LICENSE +0 -0
  26. {tmcode-0.2.0 → tmcode-0.3.1}/setup.cfg +0 -0
  27. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/buffers.py +0 -0
  28. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/completions.py +0 -0
  29. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/findbar.py +0 -0
  30. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/formatting.py +0 -0
  31. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/search.py +0 -0
  32. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/theme.py +0 -0
  33. {tmcode-0.2.0 → tmcode-0.3.1}/src/termcode/workspace.py +0 -0
  34. {tmcode-0.2.0 → tmcode-0.3.1}/src/tmcode.egg-info/dependency_links.txt +0 -0
  35. {tmcode-0.2.0 → tmcode-0.3.1}/src/tmcode.egg-info/entry_points.txt +0 -0
  36. {tmcode-0.2.0 → tmcode-0.3.1}/src/tmcode.egg-info/requires.txt +0 -0
  37. {tmcode-0.2.0 → tmcode-0.3.1}/src/tmcode.egg-info/top_level.txt +0 -0
  38. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_buffers.py +0 -0
  39. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_commands.py +0 -0
  40. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_completions.py +0 -0
  41. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_foreground.py +0 -0
  42. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_formatting.py +0 -0
  43. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_highlighting.py +0 -0
  44. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_search.py +0 -0
  45. {tmcode-0.2.0 → tmcode-0.3.1}/tests/test_workspace.py +0 -0
tmcode-0.3.1/PKG-INFO ADDED
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.4
2
+ Name: tmcode
3
+ Version: 0.3.1
4
+ Summary: TmCode: a lightweight terminal code editor for any language: highlight and run code, find/replace, format on save
5
+ Author: Abdullah Al Mamun
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/abdullahalmamun29/tmcode
8
+ Project-URL: Issues, https://github.com/abdullahalmamun29/tmcode/issues
9
+ Keywords: editor,terminal,tui,ide,textual
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Text Editors
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: textual[syntax]>=0.80.0
21
+ Requires-Dist: tree-sitter-c>=0.23.0
22
+ Requires-Dist: tree-sitter-cpp>=0.23.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
25
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # TmCode
29
+
30
+ Lightweight, cross-platform VS Code-style terminal code editor for **any language**: open, highlight and run code right in your terminal.
31
+
32
+ ## Features
33
+
34
+ - Launch right from any terminal (`tmcode` from `~` opens the Home folder picker; `tmcode` inside any project folder opens it directly)
35
+ - VS Code Dark Modern 3-pane layout: Explorer with `+F`/`+D` buttons, multi-tab + side-by-side split editor (`F12`), and draggable/resizable Terminal panel
36
+ - Syntax colors for **hundreds of languages**: precise tree-sitter highlighting for Python, C, C++, JS/TS, HTML, CSS, JSON, Java, Go, Rust, Bash, SQL, Markdown, YAML, TOML, XML and Regex, plus Pygments for everything else (Kotlin, Swift, C#, Haskell, Elixir, Zig, Dart, R, Julia, Dockerfile, ...)
37
+ - Lightweight offline code suggestions (language builtins + open-file words) and automatic indentation while typing
38
+ - Auto-closing brackets and quotes like VS Code: `(` `[` `{` `"` `'` insert their partner, typing the closer steps over it, Backspace removes an empty pair, Enter inside `{}` opens an indented block, and typing a bracket with text selected wraps it
39
+ - Run any language with `F5` (live keyboard input) or `Shift+F5` (full terminal): Python, C, C++, JavaScript, TypeScript, Bash, Go, Rust, Java, Ruby, PHP, Perl, Lua, Kotlin, Swift, Dart, C#, F#, Haskell, Elixir, Erlang, R, Julia, Scala, Zig, Nim, Crystal, D, Fortran, Pascal, Ada, COBOL, OCaml, Clojure, Groovy, PowerShell, Zsh, Fish, Tcl, Racket, Scheme, Common Lisp, Raku, AWK, Octave, CoffeeScript, Mojo, Odin, Vala and SQL (SQLite). Any script with a `#!` line runs too, and you can add your own commands (see [Run any language](#run-any-language))
40
+ - Web files too: `F5` on an `.html` page opens it in your browser (on a `.css`/`.scss` file it opens the page next to it), `.jsx`/`.tsx` run with `tsx`, `bun` or `deno`, and HTML, CSS, SCSS, Less, Vue, Svelte, Astro, PHP, EJS, Nunjucks and Handlebars all get colors. For framework projects (React, Vue, Next.js...) press `Ctrl+T` and run `npm run dev` in your own shell
41
+ - Update prompt on start, like Codex: **Update now**, **Skip**, or **Skip until next version** (checks at most once a day; turn off with `TMCODE_NO_UPDATE_CHECK=1`). `tmcode --update` updates any time
42
+ - Real OS clipboard integration (Linux X11/Wayland, macOS, Windows), `Ctrl+A` select-all, and VS Code-style `Ctrl+C` (copies selection or current line)
43
+ - Searchable `/` command menu (`Ctrl+K` anywhere, or `/` outside text inputs) with a shortcut for every action
44
+
45
+ ## Installation
46
+
47
+ One command, no Python needed:
48
+
49
+ **macOS / Linux**
50
+ ```bash
51
+ curl -fsSL https://raw.githubusercontent.com/abdullahalmamun29/tmcode/main/install.sh | sh
52
+ ```
53
+
54
+ **Windows** (PowerShell)
55
+ ```powershell
56
+ powershell -ExecutionPolicy Bypass -c "irm https://raw.githubusercontent.com/abdullahalmamun29/tmcode/main/install.ps1 | iex"
57
+ ```
58
+
59
+ Then open a new terminal and run `tmcode` inside a project folder.
60
+
61
+ The installer downloads the ready-made TmCode for your system from [Releases](https://github.com/abdullahalmamun29/tmcode/releases) (and checks its SHA-256). If there is none for your system, it installs TmCode with [uv](https://docs.astral.sh/uv/) instead, which fetches Python by itself.
62
+
63
+ - **Update:** run the same command again.
64
+ - **Uninstall (macOS / Linux):** `rm -rf ~/.local/share/tmcode ~/.local/bin/tmcode ~/.local/bin/termcode`
65
+ - **Uninstall (Windows):** delete `%LOCALAPPDATA%\tmcode` and remove it from your user PATH.
66
+
67
+ ### Already have Python? Install from PyPI
68
+
69
+ ```bash
70
+ pipx install tmcode # or: uv tool install tmcode
71
+ ```
72
+
73
+ ### Good to know
74
+ - To **run** code you need the language itself installed: `python3`, `gcc`/`g++` for C/C++, `node`, `go`, `rustc`, `java`, etc.
75
+ - **Format on save** works out of the box with a built-in re-indenter. If `ruff`/`black`, `clang-format`, `prettier`, `gofmt` or `rustfmt` are installed, TmCode uses them automatically.
76
+ - On Windows use **Windows Terminal**. The resize pointer (↔ ↕ on panel edges) shows in kitty, WezTerm, Ghostty, foot and xterm; other terminals show the highlighted grip instead.
77
+
78
+ ### From source (for development)
79
+ ```bash
80
+ git clone https://github.com/abdullahalmamun29/tmcode.git
81
+ cd tmcode
82
+ python3 -m venv .venv
83
+ .venv/bin/pip install -e ".[dev]"
84
+ .venv/bin/pytest
85
+ ```
86
+
87
+ ### Making a release (maintainers)
88
+ Bump `version` in `pyproject.toml`, commit, then push a tag:
89
+ ```bash
90
+ git tag v0.2.1 && git push origin v0.2.1
91
+ ```
92
+ GitHub Actions runs the tests, builds TmCode for Linux, macOS (Intel + Apple Silicon) and Windows, and publishes a Release with checksums. See `.github/workflows/release.yml` to also publish to PyPI automatically.
93
+
94
+ ## Run any language
95
+
96
+ `F5` picks the right command from the file extension. You need that language installed (for example `kotlinc` for `.kt`); if it's missing, TmCode tells you what to install.
97
+
98
+ For anything else:
99
+
100
+ - **`#!` line:** a first line like `#!/usr/bin/env ruby` tells TmCode how to run the file, even with no extension.
101
+ - **Your own commands:** create `run-commands.json` in TmCode's settings folder (`~/.config/termcode/` on Linux, `~/Library/Application Support/termcode/` on macOS, `%LOCALAPPDATA%\termcode\termcode\` on Windows). Your commands also override the built-in ones:
102
+
103
+ ```json
104
+ {
105
+ ".foo": "foo-run {file}",
106
+ ".py": "python3 -X dev {file}",
107
+ ".bar": { "compile": "barc {file} -o {out}", "run": "{out}" }
108
+ }
109
+ ```
110
+
111
+ Placeholders: `{file}` the file, `{out}` a temporary program path for compiled languages, `{dir}` the file's folder, `{stem}` the file name without extension.
112
+
113
+ ## Usage
114
+
115
+ ```bash
116
+ tmcode # From ~ opens the Home tab (folder selector & recent folders); from any project folder opens it directly
117
+ tmcode . # Open current directory directly (from ~ this still shows the start page)
118
+ tmcode path/to/project # Open a specific folder
119
+ tmcode path/to/main.py # Open a specific file and its folder
120
+ ```
121
+
122
+ ## `/` Command Menu & Shortcuts
123
+
124
+ Open the menu anytime with **`Ctrl+K`**, or press **`/`** when focus is on the file tree or terminal log.
125
+
126
+ | Command | Shortcut | Action |
127
+ |---|---|---|
128
+ | `/run` | `F5` | Save and run active file in Terminal panel |
129
+ | `/stop` | `F7` | Stop currently running program |
130
+ | `/save` | `Ctrl+S` | Save active file |
131
+ | `/save-as` | `F8` | Save current buffer under a new name |
132
+ | `/new-file` | `Ctrl+N` | Create a new file in the selected folder |
133
+ | `/new-folder` | `F3` | Create a new folder in the selected folder |
134
+ | `/open-file` | `Ctrl+P` | Quick-select and open a file in this folder |
135
+ | `/open-folder` | `Ctrl+O` | Browse & open another folder as workspace root |
136
+ | `/rename` | `F2` | Rename selected file or folder |
137
+ | `/delete` | `F4` | Delete selected file or folder (with confirmation) |
138
+ | `/toggle-sidebar` | `Ctrl+B` | Show or hide the Explorer sidebar |
139
+ | `/toggle-terminal` | `Ctrl+J` | Show or hide the bottom Terminal panel |
140
+ | `/toggle-hidden` | `F9` | Show or hide hidden dotfiles in Explorer |
141
+ | `/terminal-grow` | `Ctrl+Up` | Increase Terminal panel height (or drag header bar) |
142
+ | `/terminal-shrink` | `Ctrl+Down` | Decrease Terminal panel height (or drag header bar) |
143
+ | `/copy-output` | `F10` | Copy selected or full Terminal output |
144
+ | `/clear-output` | `Ctrl+L` | Clear the Terminal output |
145
+ | `/next-tab` | `F11` | Switch to the next open file tab |
146
+ | `/close-tab` | `Ctrl+W` | Close the current file tab |
147
+ | `/split-editor` | `F12` | Toggle side-by-side split editor |
148
+ | `/quit` | `Ctrl+Q` | Exit TmCode |
149
+
150
+ ## Running Tests
151
+
152
+ ```bash
153
+ .venv/bin/pytest -v
154
+ ```
155
+
156
+ ## License
157
+
158
+ MIT © 2026 Abdullah Al Mamun. See [LICENSE](LICENSE).
tmcode-0.3.1/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # TmCode
2
+
3
+ Lightweight, cross-platform VS Code-style terminal code editor for **any language**: open, highlight and run code right in your terminal.
4
+
5
+ ## Features
6
+
7
+ - Launch right from any terminal (`tmcode` from `~` opens the Home folder picker; `tmcode` inside any project folder opens it directly)
8
+ - VS Code Dark Modern 3-pane layout: Explorer with `+F`/`+D` buttons, multi-tab + side-by-side split editor (`F12`), and draggable/resizable Terminal panel
9
+ - Syntax colors for **hundreds of languages**: precise tree-sitter highlighting for Python, C, C++, JS/TS, HTML, CSS, JSON, Java, Go, Rust, Bash, SQL, Markdown, YAML, TOML, XML and Regex, plus Pygments for everything else (Kotlin, Swift, C#, Haskell, Elixir, Zig, Dart, R, Julia, Dockerfile, ...)
10
+ - Lightweight offline code suggestions (language builtins + open-file words) and automatic indentation while typing
11
+ - Auto-closing brackets and quotes like VS Code: `(` `[` `{` `"` `'` insert their partner, typing the closer steps over it, Backspace removes an empty pair, Enter inside `{}` opens an indented block, and typing a bracket with text selected wraps it
12
+ - Run any language with `F5` (live keyboard input) or `Shift+F5` (full terminal): Python, C, C++, JavaScript, TypeScript, Bash, Go, Rust, Java, Ruby, PHP, Perl, Lua, Kotlin, Swift, Dart, C#, F#, Haskell, Elixir, Erlang, R, Julia, Scala, Zig, Nim, Crystal, D, Fortran, Pascal, Ada, COBOL, OCaml, Clojure, Groovy, PowerShell, Zsh, Fish, Tcl, Racket, Scheme, Common Lisp, Raku, AWK, Octave, CoffeeScript, Mojo, Odin, Vala and SQL (SQLite). Any script with a `#!` line runs too, and you can add your own commands (see [Run any language](#run-any-language))
13
+ - Web files too: `F5` on an `.html` page opens it in your browser (on a `.css`/`.scss` file it opens the page next to it), `.jsx`/`.tsx` run with `tsx`, `bun` or `deno`, and HTML, CSS, SCSS, Less, Vue, Svelte, Astro, PHP, EJS, Nunjucks and Handlebars all get colors. For framework projects (React, Vue, Next.js...) press `Ctrl+T` and run `npm run dev` in your own shell
14
+ - Update prompt on start, like Codex: **Update now**, **Skip**, or **Skip until next version** (checks at most once a day; turn off with `TMCODE_NO_UPDATE_CHECK=1`). `tmcode --update` updates any time
15
+ - Real OS clipboard integration (Linux X11/Wayland, macOS, Windows), `Ctrl+A` select-all, and VS Code-style `Ctrl+C` (copies selection or current line)
16
+ - Searchable `/` command menu (`Ctrl+K` anywhere, or `/` outside text inputs) with a shortcut for every action
17
+
18
+ ## Installation
19
+
20
+ One command, no Python needed:
21
+
22
+ **macOS / Linux**
23
+ ```bash
24
+ curl -fsSL https://raw.githubusercontent.com/abdullahalmamun29/tmcode/main/install.sh | sh
25
+ ```
26
+
27
+ **Windows** (PowerShell)
28
+ ```powershell
29
+ powershell -ExecutionPolicy Bypass -c "irm https://raw.githubusercontent.com/abdullahalmamun29/tmcode/main/install.ps1 | iex"
30
+ ```
31
+
32
+ Then open a new terminal and run `tmcode` inside a project folder.
33
+
34
+ The installer downloads the ready-made TmCode for your system from [Releases](https://github.com/abdullahalmamun29/tmcode/releases) (and checks its SHA-256). If there is none for your system, it installs TmCode with [uv](https://docs.astral.sh/uv/) instead, which fetches Python by itself.
35
+
36
+ - **Update:** run the same command again.
37
+ - **Uninstall (macOS / Linux):** `rm -rf ~/.local/share/tmcode ~/.local/bin/tmcode ~/.local/bin/termcode`
38
+ - **Uninstall (Windows):** delete `%LOCALAPPDATA%\tmcode` and remove it from your user PATH.
39
+
40
+ ### Already have Python? Install from PyPI
41
+
42
+ ```bash
43
+ pipx install tmcode # or: uv tool install tmcode
44
+ ```
45
+
46
+ ### Good to know
47
+ - To **run** code you need the language itself installed: `python3`, `gcc`/`g++` for C/C++, `node`, `go`, `rustc`, `java`, etc.
48
+ - **Format on save** works out of the box with a built-in re-indenter. If `ruff`/`black`, `clang-format`, `prettier`, `gofmt` or `rustfmt` are installed, TmCode uses them automatically.
49
+ - On Windows use **Windows Terminal**. The resize pointer (↔ ↕ on panel edges) shows in kitty, WezTerm, Ghostty, foot and xterm; other terminals show the highlighted grip instead.
50
+
51
+ ### From source (for development)
52
+ ```bash
53
+ git clone https://github.com/abdullahalmamun29/tmcode.git
54
+ cd tmcode
55
+ python3 -m venv .venv
56
+ .venv/bin/pip install -e ".[dev]"
57
+ .venv/bin/pytest
58
+ ```
59
+
60
+ ### Making a release (maintainers)
61
+ Bump `version` in `pyproject.toml`, commit, then push a tag:
62
+ ```bash
63
+ git tag v0.2.1 && git push origin v0.2.1
64
+ ```
65
+ GitHub Actions runs the tests, builds TmCode for Linux, macOS (Intel + Apple Silicon) and Windows, and publishes a Release with checksums. See `.github/workflows/release.yml` to also publish to PyPI automatically.
66
+
67
+ ## Run any language
68
+
69
+ `F5` picks the right command from the file extension. You need that language installed (for example `kotlinc` for `.kt`); if it's missing, TmCode tells you what to install.
70
+
71
+ For anything else:
72
+
73
+ - **`#!` line:** a first line like `#!/usr/bin/env ruby` tells TmCode how to run the file, even with no extension.
74
+ - **Your own commands:** create `run-commands.json` in TmCode's settings folder (`~/.config/termcode/` on Linux, `~/Library/Application Support/termcode/` on macOS, `%LOCALAPPDATA%\termcode\termcode\` on Windows). Your commands also override the built-in ones:
75
+
76
+ ```json
77
+ {
78
+ ".foo": "foo-run {file}",
79
+ ".py": "python3 -X dev {file}",
80
+ ".bar": { "compile": "barc {file} -o {out}", "run": "{out}" }
81
+ }
82
+ ```
83
+
84
+ Placeholders: `{file}` the file, `{out}` a temporary program path for compiled languages, `{dir}` the file's folder, `{stem}` the file name without extension.
85
+
86
+ ## Usage
87
+
88
+ ```bash
89
+ tmcode # From ~ opens the Home tab (folder selector & recent folders); from any project folder opens it directly
90
+ tmcode . # Open current directory directly (from ~ this still shows the start page)
91
+ tmcode path/to/project # Open a specific folder
92
+ tmcode path/to/main.py # Open a specific file and its folder
93
+ ```
94
+
95
+ ## `/` Command Menu & Shortcuts
96
+
97
+ Open the menu anytime with **`Ctrl+K`**, or press **`/`** when focus is on the file tree or terminal log.
98
+
99
+ | Command | Shortcut | Action |
100
+ |---|---|---|
101
+ | `/run` | `F5` | Save and run active file in Terminal panel |
102
+ | `/stop` | `F7` | Stop currently running program |
103
+ | `/save` | `Ctrl+S` | Save active file |
104
+ | `/save-as` | `F8` | Save current buffer under a new name |
105
+ | `/new-file` | `Ctrl+N` | Create a new file in the selected folder |
106
+ | `/new-folder` | `F3` | Create a new folder in the selected folder |
107
+ | `/open-file` | `Ctrl+P` | Quick-select and open a file in this folder |
108
+ | `/open-folder` | `Ctrl+O` | Browse & open another folder as workspace root |
109
+ | `/rename` | `F2` | Rename selected file or folder |
110
+ | `/delete` | `F4` | Delete selected file or folder (with confirmation) |
111
+ | `/toggle-sidebar` | `Ctrl+B` | Show or hide the Explorer sidebar |
112
+ | `/toggle-terminal` | `Ctrl+J` | Show or hide the bottom Terminal panel |
113
+ | `/toggle-hidden` | `F9` | Show or hide hidden dotfiles in Explorer |
114
+ | `/terminal-grow` | `Ctrl+Up` | Increase Terminal panel height (or drag header bar) |
115
+ | `/terminal-shrink` | `Ctrl+Down` | Decrease Terminal panel height (or drag header bar) |
116
+ | `/copy-output` | `F10` | Copy selected or full Terminal output |
117
+ | `/clear-output` | `Ctrl+L` | Clear the Terminal output |
118
+ | `/next-tab` | `F11` | Switch to the next open file tab |
119
+ | `/close-tab` | `Ctrl+W` | Close the current file tab |
120
+ | `/split-editor` | `F12` | Toggle side-by-side split editor |
121
+ | `/quit` | `Ctrl+Q` | Exit TmCode |
122
+
123
+ ## Running Tests
124
+
125
+ ```bash
126
+ .venv/bin/pytest -v
127
+ ```
128
+
129
+ ## License
130
+
131
+ MIT © 2026 Abdullah Al Mamun. See [LICENSE](LICENSE).
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tmcode"
7
- version = "0.2.0"
8
- description = "TmCode: a lightweight terminal code editor with run, find/replace, format-on-save and a real-terminal mode"
7
+ version = "0.3.1"
8
+ description = "TmCode: a lightweight terminal code editor for any language: highlight and run code, find/replace, format on save"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  license = "MIT"
@@ -1,3 +1,3 @@
1
1
  """TermCode — lightweight terminal code editor and runner."""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.3.1"
@@ -16,6 +16,7 @@ from textual.app import App, ComposeResult, SuspendNotSupported
16
16
  from textual.binding import Binding
17
17
  from textual.containers import Horizontal, Vertical
18
18
  from textual.css.query import NoMatches
19
+ from textual.widgets.text_area import Selection
19
20
  from textual.widgets import Button, DirectoryTree, Input, OptionList, Static, TextArea
20
21
  from textual.widgets.option_list import Option
21
22
 
@@ -29,7 +30,8 @@ from termcode.completions import (
29
30
  from termcode import __version__, theme
30
31
  from termcode.findbar import FindBar
31
32
  from termcode.formatting import format_code
32
- from termcode.highlighting import register_extra_languages
33
+ from termcode.highlighting import pygments_highlights, pygments_lexer_for, register_extra_languages
34
+ from termcode.pairs import CLOSERS, PAIRS, plan_backspace, plan_enter, plan_typed
33
35
  from termcode.modals import (
34
36
  CommandPaletteModal,
35
37
  ConfirmModal,
@@ -37,6 +39,14 @@ from termcode.modals import (
37
39
  FolderPickerModal,
38
40
  TextInputModal,
39
41
  UnsavedChangesModal,
42
+ UpdateModal,
43
+ )
44
+ from termcode.update import (
45
+ InstallKind,
46
+ check_for_update,
47
+ default_state_path,
48
+ detect_install,
49
+ skip_version,
40
50
  )
41
51
  from termcode.search import parse_goto
42
52
  from termcode.runner import (
@@ -300,6 +310,27 @@ class CodeTextArea(TextArea):
300
310
  self.register_theme(theme.OUTPUT_THEME)
301
311
  self.theme = theme.OUTPUT_THEME_NAME if self.read_only else theme.EDITOR_THEME_NAME
302
312
 
313
+ # Pygments lexer used when the file's language has no tree-sitter grammar.
314
+ _fallback_lexer = None
315
+
316
+ def set_fallback_lexer(self, lexer) -> None: # type: ignore[no-untyped-def]
317
+ if lexer is None and self._fallback_lexer is None:
318
+ return
319
+ self._fallback_lexer = lexer
320
+ self._build_highlight_map()
321
+ self.refresh()
322
+
323
+ def _build_highlight_map(self) -> None:
324
+ if self._fallback_lexer is None or self.language is not None:
325
+ super()._build_highlight_map()
326
+ return
327
+ self._line_cache.clear()
328
+ self._highlights.clear()
329
+ try:
330
+ self._highlights.update(pygments_highlights(self.text, self._fallback_lexer))
331
+ except Exception:
332
+ pass # never let coloring break editing
333
+
303
334
  def action_copy(self) -> None:
304
335
  """Copy selected text, or the current line when nothing is selected (VS Code behavior)."""
305
336
  selected = self.selected_text
@@ -348,6 +379,11 @@ class CodeTextArea(TextArea):
348
379
  event.stop()
349
380
  return
350
381
 
382
+ if self._handle_pairs(event):
383
+ event.prevent_default()
384
+ event.stop()
385
+ return
386
+
351
387
  if event.key == "enter":
352
388
  row, col = self.cursor_location
353
389
  line_before = self.document.get_line(row)[:col]
@@ -369,6 +405,53 @@ class CodeTextArea(TextArea):
369
405
 
370
406
  await super()._on_key(event)
371
407
 
408
+ def _handle_pairs(self, event: events.Key) -> bool:
409
+ """Auto-close brackets/quotes, step over closers, delete empty pairs. True if handled."""
410
+ char = event.character or ""
411
+ selection = self.selection
412
+ has_selection = selection.start != selection.end
413
+
414
+ if has_selection:
415
+ if char not in PAIRS:
416
+ return False
417
+ # Wrap the selection: select `abc`, type ( → (abc), still selected.
418
+ start, end = sorted((selection.start, selection.end))
419
+ inner = self.selected_text
420
+ self.replace(char + inner + PAIRS[char], start, end)
421
+ end_col = end[1] + 1 if start[0] == end[0] else end[1]
422
+ self.selection = Selection((start[0], start[1] + 1), (end[0], end_col))
423
+ return True
424
+
425
+ row, col = self.cursor_location
426
+ line = self.document.get_line(row)
427
+
428
+ if event.key == "backspace":
429
+ span = plan_backspace(line, col)
430
+ if span is None:
431
+ return False
432
+ self.delete((row, span[0]), (row, span[1]))
433
+ return True
434
+
435
+ if event.key == "enter":
436
+ unit = "\t" if line.startswith("\t") else " "
437
+ planned = plan_enter(line, col, unit)
438
+ if planned is None:
439
+ return False
440
+ text, offset = planned
441
+ self.insert(text)
442
+ self.move_cursor((row + 1, offset - 1))
443
+ return True
444
+
445
+ if char in PAIRS or char in CLOSERS:
446
+ edit = plan_typed(char, line, col, self.language)
447
+ if edit is None:
448
+ return False
449
+ if edit.text:
450
+ self.replace(edit.text, (row, edit.start), (row, edit.end))
451
+ self.move_cursor((row, edit.cursor))
452
+ return True
453
+ return False
454
+
372
455
 
373
456
  class FilteredDirectoryTree(DirectoryTree):
374
457
  """DirectoryTree that hides dotfiles and noisy build/cache folders by default,
@@ -482,7 +565,7 @@ class TermCodeApp(App[None]):
482
565
  """Lightweight VS Code-style terminal editor and runner for all major languages."""
483
566
 
484
567
  CSS_PATH = "styles.tcss"
485
- TITLE = "TermCode"
568
+ TITLE = "TmCode"
486
569
  ENABLE_COMMAND_PALETTE = False
487
570
 
488
571
  BINDINGS = [
@@ -543,6 +626,9 @@ class TermCodeApp(App[None]):
543
626
  self.output_visible: bool = True
544
627
  self.format_on_save: bool = True
545
628
  self._recent_store: Path | None = recent_store
629
+ # Set when the user picks "Update now"; cli.main runs the update after exit.
630
+ self.update_to: str | None = None
631
+ self.install_kind: InstallKind = detect_install()
546
632
  self._recent_folders: list[Path] = []
547
633
  self._completion_editor: CodeTextArea | None = None
548
634
  self._completion_prefix: str = ""
@@ -639,7 +725,7 @@ class TermCodeApp(App[None]):
639
725
  with Vertical(id="welcome-card"):
640
726
  yield Static(
641
727
  Text.assemble(
642
- ("termcode", f"bold {theme.TEXT}"),
728
+ ("tmcode", f"bold {theme.TEXT}"),
643
729
  (f" {__version__}", theme.FAINT),
644
730
  ),
645
731
  id="welcome-title",
@@ -666,7 +752,7 @@ class TermCodeApp(App[None]):
666
752
  markup=False,
667
753
  )
668
754
  yield Static(
669
- "Run termcode inside a project folder to skip this screen.",
755
+ "Run tmcode inside a project folder to skip this screen.",
670
756
  id="welcome-tip",
671
757
  markup=False,
672
758
  )
@@ -741,6 +827,8 @@ class TermCodeApp(App[None]):
741
827
  self.query_one("#find-bar").display = False
742
828
  self._set_run_state("idle")
743
829
  self._refresh_recent_list()
830
+ if not self.is_headless:
831
+ self.run_worker(self._check_for_update, thread=True, group="update-check", exit_on_error=False)
744
832
 
745
833
  if self.workspace_root is not None:
746
834
  record_recent_folder(self.workspace_root, store_path=self._recent_store)
@@ -807,9 +895,13 @@ class TermCodeApp(App[None]):
807
895
  def _apply_editor_language(self, editor: CodeTextArea, path: Path | None) -> None:
808
896
  wanted = editor_language_for_path(path)
809
897
  if wanted and wanted in editor.available_languages:
898
+ editor.set_fallback_lexer(None)
810
899
  editor.language = wanted
811
900
  else:
812
901
  editor.language = None
902
+ # No tree-sitter grammar: color it with Pygments (hundreds of languages).
903
+ lexer = pygments_lexer_for(path.name, editor.text) if path is not None else None
904
+ editor.set_fallback_lexer(lexer)
813
905
 
814
906
  def _sync_buffer_from_editor(self, pane_id: str) -> None:
815
907
  pane = self._pane_for_id(pane_id)
@@ -869,6 +961,7 @@ class TermCodeApp(App[None]):
869
961
  self._suppress_dirty = True
870
962
  try:
871
963
  if buf is None:
964
+ editor.set_fallback_lexer(None)
872
965
  editor.text = ""
873
966
  editor.language = None
874
967
  else:
@@ -1657,7 +1750,7 @@ class TermCodeApp(App[None]):
1657
1750
  return True
1658
1751
 
1659
1752
  def action_open_shell(self) -> None:
1660
- """Ctrl+T: open the user's own shell; `exit` comes back to TermCode."""
1753
+ """Ctrl+T: open the user's own shell; `exit` comes back to TmCode."""
1661
1754
  if not self._on_main_screen():
1662
1755
  return
1663
1756
  if self.runner.is_running:
@@ -1669,7 +1762,7 @@ class TermCodeApp(App[None]):
1669
1762
 
1670
1763
  def _shell() -> None:
1671
1764
  self._tty_write(
1672
- f"\x1b[2J\x1b[H\x1b[2mTermCode is paused. You're in {cwd}. "
1765
+ f"\x1b[2J\x1b[H\x1b[2mTmCode is paused. You're in {cwd}. "
1673
1766
  "Type exit to come back.\x1b[0m\n"
1674
1767
  )
1675
1768
  try:
@@ -2220,6 +2313,40 @@ class TermCodeApp(App[None]):
2220
2313
  self.output_history = ""
2221
2314
  self.query_one("#output-log", CodeTextArea).load_text("")
2222
2315
 
2316
+ # ---------- update check ----------
2317
+
2318
+ def _update_state_path(self) -> Path:
2319
+ if self._recent_store is not None:
2320
+ return self._recent_store.parent / "update.json"
2321
+ return default_state_path()
2322
+
2323
+ def _check_for_update(self) -> None:
2324
+ """Runs in a thread at startup; network at most once a day, silent on failure."""
2325
+ latest = check_for_update(__version__, self.install_kind, self._update_state_path())
2326
+ if latest:
2327
+ self.call_from_thread(self._prompt_update, latest)
2328
+
2329
+ def _prompt_update(self, latest: str) -> None:
2330
+ how = {
2331
+ InstallKind.BINARY: "Update now downloads it and closes TmCode.",
2332
+ InstallKind.PIPX: "Update now runs pipx upgrade tmcode and closes TmCode.",
2333
+ InstallKind.UV: "Update now runs uv tool upgrade tmcode and closes TmCode.",
2334
+ InstallKind.PIP: "Update now runs pip install --upgrade tmcode and closes TmCode.",
2335
+ }.get(self.install_kind, "")
2336
+
2337
+ def _chosen(choice: str | None) -> None:
2338
+ if choice == "update":
2339
+ def _go() -> None:
2340
+ self.update_to = latest
2341
+ self._shutdown_and_exit()
2342
+
2343
+ self._guard_all_unsaved(_go)
2344
+ elif choice == "skip-version":
2345
+ skip_version(self._update_state_path(), latest)
2346
+ self.notify(f"Skipped {latest}. You'll be asked again when a newer version is out.")
2347
+
2348
+ self.push_screen(UpdateModal(latest, __version__, how), _chosen)
2349
+
2223
2350
  def action_request_quit(self) -> None:
2224
2351
  if not self._on_main_screen():
2225
2352
  return
@@ -8,6 +8,7 @@ import sys
8
8
 
9
9
  from termcode import __version__
10
10
  from termcode.app import TermCodeApp
11
+ from termcode.update import detect_install, run_update
11
12
 
12
13
 
13
14
  def _is_home(path: Path) -> bool:
@@ -34,7 +35,7 @@ def parse_cli_target(arg: str | None, cwd: Path | None = None) -> tuple[Path | N
34
35
  target = base / target
35
36
 
36
37
  if not target.exists():
37
- raise SystemExit(f"termcode: path not found: {arg}")
38
+ raise SystemExit(f"tmcode: path not found: {arg}")
38
39
 
39
40
  resolved = target.resolve()
40
41
  if resolved.is_dir():
@@ -44,8 +45,8 @@ def parse_cli_target(arg: str | None, cwd: Path | None = None) -> tuple[Path | N
44
45
 
45
46
  def main(argv: list[str] | None = None) -> int:
46
47
  parser = argparse.ArgumentParser(
47
- prog="termcode",
48
- description="Lightweight VS Code-style terminal editor and runner for Python, C, and C++.",
48
+ prog="tmcode",
49
+ description="TmCode: a lightweight terminal code editor. Edit and run code in any language.",
49
50
  )
50
51
  parser.add_argument(
51
52
  "path",
@@ -53,15 +54,24 @@ def main(argv: list[str] | None = None) -> int:
53
54
  default=None,
54
55
  help="Optional folder or file to open (from home directory, opens the Home folder selector; from any other folder, opens it directly).",
55
56
  )
57
+ parser.add_argument(
58
+ "--update",
59
+ action="store_true",
60
+ help="Update TmCode to the latest version and exit.",
61
+ )
56
62
  parser.add_argument(
57
63
  "--version",
58
64
  action="version",
59
65
  version=f"%(prog)s {__version__}",
60
66
  )
61
67
  args = parser.parse_args(argv)
68
+ if args.update:
69
+ return run_update(detect_install())
62
70
  workspace_root, initial_file = parse_cli_target(args.path)
63
71
  app = TermCodeApp(workspace_root=workspace_root, initial_file=initial_file)
64
72
  app.run()
73
+ if app.update_to:
74
+ return run_update(app.install_kind, app.update_to)
65
75
  return 0
66
76
 
67
77
 
@@ -209,7 +209,7 @@ COMMANDS: tuple[CommandSpec, ...] = (
209
209
  action="request_quit",
210
210
  shortcut="Ctrl+Q",
211
211
  binding="ctrl+q",
212
- description="Exit TermCode",
212
+ description="Exit TmCode",
213
213
  ),
214
214
  )
215
215