-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 0482349
Showing
6 changed files
with
263 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.9" | ||
- name: install | ||
run: | | ||
pip install poetry | ||
poetry install | ||
- name: publish | ||
run: | | ||
poetry publish -n -u __token__ -p ${{ secrets.PYPI_TOKEN }} --build |
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,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2021, m9810223 | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,25 @@ | ||
# pymatrix | ||
|
||
[](https://pypi.org/project/pymatrix-ss/) | ||
|
||
## Screensaver with zsh-morpho | ||
|
||
 | ||
|
||
1. Install | ||
|
||
```shell | ||
pip install pymatrix-ss | ||
``` | ||
|
||
[](https://pypi.org/project/pymatrix-ss/) | ||
|
||
1. Open `~/.zshrc` | ||
1. add `zsh-morpho` to `plugins` | ||
1. config zsh-morpho | ||
|
||
```shell | ||
zstyle ":morpho" screen-saver "pymatrix" | ||
zstyle ":morpho" delay "290" # 5 minutes before screen saver starts | ||
zstyle ":morpho" check-interval "60" # check every 1 minute if to run screen saver | ||
``` |
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,22 @@ | ||
[tool.poetry] | ||
authors = [" "] | ||
description = "" | ||
name = "pymatrix-ss" | ||
packages = [ | ||
{include = "pymatrix", from = "src"}, | ||
] | ||
readme = "README.md" | ||
repository = "https://github.com/m9810223/pymatrix-ss" | ||
version = "0.1.8" | ||
|
||
[tool.poetry.dependencies] | ||
python = ">3,<4" | ||
|
||
[tool.poetry.dev-dependencies] | ||
|
||
[build-system] | ||
build-backend = "poetry.core.masonry.api" | ||
requires = ["poetry-core>=1.0.0"] | ||
|
||
[tool.poetry.scripts] | ||
pymatrix = "pymatrix:screensaver" |
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,163 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import curses | ||
from os import get_terminal_size | ||
from random import choice | ||
from random import randint | ||
from time import sleep | ||
|
||
|
||
PARAMETERS = { | ||
'chars': ''.join( | ||
( | ||
chr(x) | ||
for r in ( | ||
range(*_) | ||
for _ in ( | ||
# (33, 34), | ||
(0x00000021, 1 + 0x0000007E), # Basic Latin | ||
(0x000000BF, 1 + 0x000000FF), # Latin-1 Supplement | ||
(0x00000100, 1 + 0x0000017F), # Latin Extended-A | ||
(0x00000180, 1 + 0x0000024F), # Latin Extended-B | ||
(0x00000250, 1 + 0x000002AF), # IPA | ||
(0x000002B0, 1 + 0x000002FF), # Spacing Modifier Letters | ||
) | ||
) | ||
for x in r | ||
) | ||
), | ||
'whites': [255], | ||
'greens': [47, 35], | ||
# show when value <= 0, green when value < 0, white when value = 0 | ||
'show': [-16, -8, 32, 128], | ||
'speed': 512, # BPM | ||
} | ||
|
||
|
||
def init(): | ||
window = curses.initscr() | ||
curses.noecho() | ||
curses.cbreak(True) | ||
window.keypad(True) | ||
try: | ||
curses.start_color() | ||
except: | ||
pass | ||
curses.use_default_colors() | ||
|
||
for i in range(curses.COLORS): | ||
curses.init_pair(i, i - 1, -1) | ||
|
||
return window | ||
|
||
|
||
def deinit(window: curses.window): | ||
window.keypad(False) | ||
curses.echo(True) | ||
curses.nocbreak() | ||
curses.endwin() | ||
|
||
|
||
def _get_color(i): | ||
return i, choice(PARAMETERS['greens' if i < 0 else 'whites']) | ||
|
||
|
||
def _refresh(i, c): | ||
''' | ||
= 0 -> negative | ||
=-1 -> positive | ||
> 0 -> -1 | ||
<-1 -> +1 | ||
''' | ||
if i == 0: | ||
res = randint(*PARAMETERS['show'][:2]) | ||
elif i == -1: | ||
res = randint(*PARAMETERS['show'][2:]) | ||
elif i > 0: | ||
res = i - 1 | ||
elif i < -1: | ||
res = i + 1 | ||
return _get_color(res) | ||
|
||
|
||
def get_nstr(columns, lines): | ||
show = [ | ||
[ | ||
_get_color(randint(PARAMETERS['show'][0], PARAMETERS['show'][-1])) | ||
for c in range(columns) | ||
] | ||
] | ||
while len(show) < lines: | ||
show = [[_refresh(*s) for s in show[0]]] + show | ||
char = [[choice(PARAMETERS['chars']) for c in range(columns)] for l in range(lines)] | ||
while True: | ||
for l in range(len(show)): | ||
for c in range(len(show[l])): | ||
if show[l][c] == -1: | ||
char[l][c] = choice(PARAMETERS['chars']) | ||
show = [[_refresh(*s) for s in show[0]]] + show[:-1] | ||
yield show, char | ||
|
||
|
||
def render(window: curses.window, show, char): | ||
for l in range(len(show)): | ||
for c in range(len(show[l]) - 1): | ||
window.addstr( | ||
l, | ||
c, | ||
char[l][c] if show[l][c][0] <= 0 else ' ', | ||
curses.color_pair(show[l][c][1]), | ||
) | ||
|
||
|
||
def main(window: curses.window): | ||
terminal_size = get_terminal_size() | ||
nstr = get_nstr(*terminal_size) | ||
window.timeout(0) | ||
while terminal_size == get_terminal_size(): | ||
try: | ||
k = window.getkey() | ||
except: | ||
pass | ||
else: | ||
if k != 'KEY_RESIZE': | ||
return k | ||
show, char = next(nstr) | ||
render(window, show, char) | ||
window.refresh() | ||
sleep(60 / PARAMETERS['speed']) | ||
|
||
|
||
def print_color_code(): | ||
def p(stdscr: curses.window): | ||
curses.start_color() | ||
curses.use_default_colors() | ||
for i in range(curses.COLORS): | ||
curses.init_pair(i + 1, i, -1) | ||
for i in range(256): | ||
stdscr.addstr(str(i), curses.color_pair(i)) | ||
stdscr.addstr(' ', curses.color_pair(i)) | ||
stdscr.getch() | ||
|
||
curses.wrapper(p) | ||
exit() | ||
|
||
|
||
def screensaver(): | ||
# print_color_code() | ||
try: | ||
while True: | ||
window = init() | ||
key = main(window) | ||
if key: | ||
exit() | ||
except KeyboardInterrupt: | ||
pass | ||
except Exception: | ||
pass | ||
finally: | ||
deinit(window) | ||
|
||
|
||
if __name__ == '__main__': | ||
screensaver() |