Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
add: 使用可能なフォント一覧の取得オプションの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Jan 19, 2024
1 parent 78b3c13 commit 97155a2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/args.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
from argparse import ArgumentParser, Namespace
import json
from argparse import Action, ArgumentParser, Namespace
from collections.abc import Sequence

from style.utils import get_font_list


class FontFamilyAction(Action):
def __init__(
self,
option_strings: Sequence[str],
dest: str,
default: str | None = None,
help: str | None = None,
) -> None:
super().__init__(
option_strings=option_strings,
dest=dest,
default=default,
nargs=0,
help=help,
)

def __call__(
self,
parser: ArgumentParser,
namespace,
values,
option_string,
) -> None:
print(json.dumps(get_font_list(), indent=2))
parser.exit()


def init_parser():
Expand Down Expand Up @@ -40,6 +71,11 @@ def init_parser():
action="store_true",
help="offline mode",
)
parser.add_argument(
"--font-family-list",
action=FontFamilyAction,
help="get font family list",
)
return parser


Expand Down
4 changes: 4 additions & 0 deletions src/style/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
}


def get_font_list():
return list(font_dict.keys())


def get_bi_font(
font_dict: dict[str, str], compromising: bool = True
) -> Optional[str]:
Expand Down

0 comments on commit 97155a2

Please sign in to comment.