Skip to content

Commit 67e6108

Browse files
author
Tage Johansson
committed
Fix default editor stuff in the comment edit command.
1 parent c5f4e29 commit 67e6108

4 files changed

Lines changed: 39 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Fixed
1616

1717
- Solve a bug which incorrectly raised an assertion when moves like "nbd2" were entered.
18+
- Hopefully fixed some errors related to editing a comment in the default editor.
1819

1920
## [0.6.0] - 2024-08-22
2021

chess_cli/curr_move_cmds.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import asyncio
12
import datetime
2-
import os
33
import re
44
import tempfile
55
from argparse import ArgumentParser
@@ -10,6 +10,7 @@
1010
import chess.engine
1111
import chess.pgn
1212
import chess.svg
13+
import click
1314
import pyperclip
1415

1516
from . import nags
@@ -216,21 +217,14 @@ def set_comment(new_comment: str) -> None:
216217
set_comment(add_to_comment_text(comment, args.comment))
217218
case "edit" | "e":
218219
fd, file_name = tempfile.mkstemp(suffix=".txt", text=True)
219-
try:
220-
with os.fdopen(fd, mode="w") as file:
221-
file.write(comment)
222-
file.flush()
223-
self.poutput(f"Opening {file_name} in your editor.")
224-
await self.exec_cmd(f"edit '{file_name}'")
225-
with open(file_name) as file:
226-
file.seek(0)
227-
new_comment: str = file.read().strip()
228-
if not args.raw:
229-
new_comment = update_comment_text(comment, new_comment)
230-
set_comment(new_comment)
231-
self.poutput("Successfully updated comment.")
232-
finally:
233-
os.remove(file_name)
220+
new_comment: str | bytes | None = await asyncio.to_thread(click.edit, comment)
221+
if isinstance(comment, bytes):
222+
comment = comment.decode()
223+
if new_comment is not None:
224+
if not args.raw:
225+
new_comment = update_comment_text(comment, new_comment)
226+
set_comment(new_comment)
227+
print(f"Successfully updated comment to:\n{new_comment}")
234228
case _:
235229
raise AssertionError("Unknown subcommand.")
236230

poetry.lock

Lines changed: 27 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ inflect = "^7.4.0"
3838
typeguard = {git = "https://github.com/tage64/typeguard"}
3939
pyperclip = "^1.9.0"
4040
progressbar2 = "^4.5.0"
41+
click = "^8.1.7"
4142

4243
[tool.poetry.group.dev.dependencies]
4344
types-requests = "^2.32.0.20241016"

0 commit comments

Comments
 (0)