-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14d883c
commit 8b77334
Showing
31 changed files
with
531 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import os | ||
import shutil | ||
|
||
|
||
def get_screen_width() -> int: | ||
terminal_size = shutil.get_terminal_size() | ||
return terminal_size.columns | ||
|
||
|
||
def get_note_content(note_path: str) -> str: | ||
if not os.path.isfile(note_path): | ||
return "" | ||
with open(note_path, "r") as f: | ||
return f.read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from zrb import MultilineInput | ||
|
||
from ._config import NOTE_ABS_FILE_PATH | ||
from ._helper import get_note_content | ||
|
||
content_input = MultilineInput( | ||
name="content", | ||
shortcut="c", | ||
comment_prefix="<!--", | ||
comment_suffix="-->", | ||
extension="md", | ||
default=lambda m: get_note_content(NOTE_ABS_FILE_PATH), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from ._group import noto_log_group | ||
from .add import add_log | ||
from .edit import edit_log | ||
from .list import list_log | ||
|
||
assert noto_log_group | ||
assert add_log | ||
assert list_log | ||
assert edit_log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import datetime | ||
import os | ||
from collections.abc import Mapping | ||
from typing import Any | ||
|
||
from zrb import MultilineInput, StrInput | ||
|
||
from .._config import CURRENT_TIME | ||
from ._helper import get_log_file_name | ||
|
||
|
||
def _get_default_content(input_map: Mapping[str, Any]) -> str: | ||
date_str = input_map.get("date") | ||
current_time = datetime.strptime(date_str, "%Y-%m-%d") | ||
file_name = get_log_file_name(current_time) | ||
if not os.path.isfile(file_name): | ||
return "" | ||
with open(file_name, "r") as f: | ||
return f.read() | ||
|
||
|
||
text_input = StrInput( | ||
name="text", | ||
shortcut="t", | ||
prompt="Text", | ||
default="", | ||
) | ||
|
||
date_input = StrInput( | ||
name="date", | ||
shortcut="d", | ||
prompt="Date (Y-m-d)", | ||
default=CURRENT_TIME.strftime("%Y-%m-%d"), | ||
) | ||
|
||
content_input = MultilineInput( | ||
name="content", | ||
shortcut="c", | ||
comment_prefix="<!--", | ||
comment_suffix="-->", | ||
extension="md", | ||
default=_get_default_content, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from datetime import datetime | ||
|
||
from zrb import Task, python_task, runner | ||
from zrb.helper.task import show_lines | ||
|
||
from .._config import IS_AUTO_SYNC | ||
from ..sync import create_sync_noto_task | ||
from ._group import noto_log_group | ||
from ._helper import get_log_file_name, get_pretty_log_lines | ||
from ._input import content_input, date_input | ||
|
||
|
||
@python_task( | ||
name="save-file", | ||
inputs=[ | ||
date_input, | ||
content_input, | ||
], | ||
retry=0, | ||
) | ||
def save_file(*args, **kwargs): | ||
date_str = kwargs.get("date") | ||
content = kwargs.get("content") | ||
current_time = datetime.strptime(date_str, "%Y-%m-%d") | ||
file_name = get_log_file_name(current_time) | ||
with open(file_name, "w") as f: | ||
f.write(content) | ||
|
||
|
||
@python_task( | ||
name="edit", | ||
group=noto_log_group, | ||
inputs=[ | ||
date_input, | ||
content_input, | ||
], | ||
retry=0, | ||
) | ||
def edit_log(*args, **kwargs): | ||
task: Task = kwargs.get("_task") | ||
date_str = kwargs.get("date") | ||
current_time = datetime.strptime(date_str, "%Y-%m-%d") | ||
file_name = get_log_file_name(current_time) | ||
show_lines(task, *get_pretty_log_lines(file_name)) | ||
|
||
|
||
if IS_AUTO_SYNC: | ||
( | ||
create_sync_noto_task(name="pre-sync") | ||
>> save_file | ||
>> create_sync_noto_task(name="post-sync") | ||
>> edit_log | ||
) | ||
else: | ||
save_file >> edit_log | ||
|
||
runner.register(edit_log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.