Skip to content

Commit 9258d64

Browse files
Once (#87)
* feat : --once argument added * doc : README.md updated * doc : CHANGELOG.md updated * fix : test.yml updated * fix : autopep8 * fix : notebook.ipynb updated * doc : CHANGELOG.md updated
1 parent 2c15456 commit 9258d64

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ jobs:
8989
- name: Run17
9090
run: |
9191
clox --date-system=jalali --date-formats-list --color="red" --bg-color="blue" --intensity="bright"
92+
- name: Run18
93+
run: |
94+
clox --date-system=jalali --once
9295
- name: Install dev-requirements
9396
run: |
9497
python otherfiles/requirements-splitter.py

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Added
99
- `--intensity` argument
10+
- `--once` argument
1011
- Light colors
1112
### Changed
1213
- `README.md` updated
1314
- Test system modified
15+
- `notebook.ipynb` updated
1416
## [1.4] - 2025-12-16
1517
### Added
1618
- `--color` argument

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ Disable blinking mode
142142
clox --no-blink
143143
```
144144

145+
### Once
146+
147+
Print current time once and exit immediately
148+
149+
```console
150+
clox --once
151+
```
152+
145153
### Hide Date
146154

147155
In this mode, the date will not be shown

clox/functions.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ def run_clock(
301301
date_system: str = "GREGORIAN",
302302
date_format: str = "FULL",
303303
offset_local: float = 0,
304-
offset_timezone: float = 0) -> None:
304+
offset_timezone: float = 0,
305+
once: bool = False) -> None:
305306
"""
306307
Run clock.
307308
@@ -319,6 +320,7 @@ def run_clock(
319320
:param date_format: date format
320321
:param offset_local: manual offset for the local time
321322
:param offset_timezone: manual offset for the timezone
323+
:param once: once flag
322324
"""
323325
try:
324326
detected_environment = detect_environment()
@@ -349,7 +351,8 @@ def run_clock(
349351
h_shift = max(0, h_shift)
350352
face = get_face(face)
351353
while True:
352-
clear_screen(detected_environment)
354+
if not once:
355+
clear_screen(detected_environment)
353356
print('\n' * v_shift, end='')
354357
print(" " * h_shift, end='')
355358
datetime_timezone = datetime_lib.datetime.now(tz=tz) + offset_main_timedelta
@@ -373,6 +376,8 @@ def run_clock(
373376
if offset_local != 0:
374377
print(" " * h_shift, end='')
375378
print(OFFSET_FORMAT.format(offset_type="Local", offset_value=offset_local))
379+
if once:
380+
break
376381
time.sleep(1)
377382
if not no_blink:
378383
format_index = int(not format_index)
@@ -400,6 +405,7 @@ def main() -> None:
400405
parser.add_argument('--hide-date', help='hide date', nargs="?", const=1)
401406
parser.add_argument('--hide-timezone', help='hide timezone', nargs="?", const=1)
402407
parser.add_argument('--am-pm', help='AM/PM mode', nargs="?", const=1)
408+
parser.add_argument('--once', help='print current time once and exit immediately', nargs='?', const=1)
403409
parser.add_argument('--calendar', help='calendar mode', type=str.upper, choices=CALENDARS_LIST)
404410
parser.add_argument('--first-weekday', help='first weekday', type=str.upper, default="MONDAY",
405411
choices=WEEKDAYS_LIST + [x[:2] for x in WEEKDAYS_LIST])
@@ -458,4 +464,5 @@ def main() -> None:
458464
date_system=args.date_system,
459465
date_format=args.date_format,
460466
offset_local=args.offset_local,
461-
offset_timezone=args.offset_timezone)
467+
offset_timezone=args.offset_timezone,
468+
once=args.once)

clox/params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@
9797
'LIGHTMAGENTA',
9898
'LIGHTCYAN',
9999
'LIGHTWHITE'
100-
]
100+
]
101101

102102
INTENSITY_LIST = ['NORMAL', 'BRIGHT', 'DIM']

notebook.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
" \"date_system\": \"GREGORIAN\", # [\"GREGORIAN\", \"JALALI\"]\n",
7373
" \"date_format\": \"FULL\", # ['DASH', 'DMY', 'DOT', 'EU', 'EU-SHORT', 'FULL', 'ISO', 'MDY', 'US', 'US-SHORT', 'YMD']\n",
7474
" \"offset_local\": 0,\n",
75-
" \"offset_timezone\": 0\n",
75+
" \"offset_timezone\": 0,\n",
76+
" \"once\": False\n",
7677
"}"
7778
]
7879
},

0 commit comments

Comments
 (0)