From 88c3562e010207bb91a2d0b35a736f24bc094e34 Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Thu, 13 Oct 2022 00:29:07 +0200 Subject: [PATCH 1/5] Move fonts outside stored_font_dicts function With this refactoring fonts dictionary can be access easily in other part of the code. --- jupyterthemes/stylefx.py | 102 +++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/jupyterthemes/stylefx.py b/jupyterthemes/stylefx.py index 95f44b6..dfa3ab5 100755 --- a/jupyterthemes/stylefx.py +++ b/jupyterthemes/stylefx.py @@ -48,6 +48,57 @@ comp_style = os.path.join(layouts_dir, 'completer.less') theme_name_file = os.path.join(jupyter_custom, 'current_theme.txt') +fonts = {'mono': + {'anka': ['Anka/Coder', 'anka-coder'], + 'anonymous': ['Anonymous Pro', 'anonymous-pro'], + 'aurulent': ['Aurulent Sans Mono', 'aurulent'], + 'bitstream': ['Bitstream Vera Sans Mono', 'bitstream-vera'], + 'bpmono': ['BPmono', 'bpmono'], + 'code': ['Code New Roman', 'code-new-roman'], + 'consolamono': ['Consolamono', 'consolamono'], + 'cousine': ['Cousine', 'cousine'], + 'dejavu': ['DejaVu Sans Mono', 'dejavu'], + 'droidmono': ['Droid Sans Mono', 'droidmono'], + 'fira': ['Fira Mono', 'fira'], + 'firacode': ['Fira Code', 'firacode'], + 'generic': ['Generic Mono', 'generic'], + 'hack': ['Hack', 'hack'], + 'hasklig': ['Hasklig', 'hasklig'], + 'iosevka' : ['Iosevka', 'iosevka'], + 'inputmono': ['Input Mono', 'inputmono'], + 'inconsolata': ['Inconsolata-g', 'inconsolata-g'], + 'liberation': ['Liberation Mono', 'liberation'], + 'meslo': ['Meslo', 'meslo'], + 'office': ['Office Code Pro', 'office-code-pro'], + 'oxygen': ['Oxygen Mono', 'oxygen'], + 'roboto': ['Roboto Mono', 'roboto'], + 'saxmono': ['saxMono', 'saxmono'], + 'source': ['Source Code Pro', 'source-code-pro'], + 'sourcemed': ['Source Code Pro Medium', 'source-code-medium'], + 'sudovar': ['Sudo Variable', 'sudo-variable'], + 'ptmono': ['PT Mono', 'ptmono'], + 'ubuntu': ['Ubuntu Mono', 'ubuntu'], + 'jetbrains' : ['JetBrains Mono', 'jetbrains'] + }, + 'sans': + {'droidsans': ['Droid Sans', 'droidsans'], + 'opensans': ['Open Sans', 'opensans'], + 'ptsans': ['PT Sans', 'ptsans'], + 'sourcesans': ['Source Sans Pro', 'sourcesans'], + 'robotosans': ['Roboto', 'robotosans'], + 'latosans': ['Lato', 'latosans'], + 'exosans': ['Exo_2', 'exosans'], + 'proxima': ['Proxima Nova', 'proximasans']}, + 'serif': + {'ptserif': ['PT Serif', 'ptserif'], + 'ebserif': ['EB Garamond', 'ebserif'], + 'loraserif': ['Lora', 'loraserif'], + 'merriserif': ['Merriweather', 'merriserif'], + 'crimsonserif': ['Crimson Text', 'crimsonserif'], + 'georgiaserif': ['Georgia', 'georgiaserif'], + 'neutonserif': ['Neuton', 'neutonserif'], + 'cardoserif': ['Cardo Serif', 'cardoserif'], + 'goudyserif': ['Goudy Serif', 'goudyserif']}} def fileOpen(filename, mode): if sys.version_info[0]==3: @@ -529,57 +580,6 @@ def get_alt_prompt_text_color(theme): def stored_font_dicts(fontcode, get_all=False): - fonts = {'mono': - {'anka': ['Anka/Coder', 'anka-coder'], - 'anonymous': ['Anonymous Pro', 'anonymous-pro'], - 'aurulent': ['Aurulent Sans Mono', 'aurulent'], - 'bitstream': ['Bitstream Vera Sans Mono', 'bitstream-vera'], - 'bpmono': ['BPmono', 'bpmono'], - 'code': ['Code New Roman', 'code-new-roman'], - 'consolamono': ['Consolamono', 'consolamono'], - 'cousine': ['Cousine', 'cousine'], - 'dejavu': ['DejaVu Sans Mono', 'dejavu'], - 'droidmono': ['Droid Sans Mono', 'droidmono'], - 'fira': ['Fira Mono', 'fira'], - 'firacode': ['Fira Code', 'firacode'], - 'generic': ['Generic Mono', 'generic'], - 'hack': ['Hack', 'hack'], - 'hasklig': ['Hasklig', 'hasklig'], - 'iosevka' : ['Iosevka', 'iosevka'], - 'inputmono': ['Input Mono', 'inputmono'], - 'inconsolata': ['Inconsolata-g', 'inconsolata-g'], - 'liberation': ['Liberation Mono', 'liberation'], - 'meslo': ['Meslo', 'meslo'], - 'office': ['Office Code Pro', 'office-code-pro'], - 'oxygen': ['Oxygen Mono', 'oxygen'], - 'roboto': ['Roboto Mono', 'roboto'], - 'saxmono': ['saxMono', 'saxmono'], - 'source': ['Source Code Pro', 'source-code-pro'], - 'sourcemed': ['Source Code Pro Medium', 'source-code-medium'], - 'sudovar': ['Sudo Variable', 'sudo-variable'], - 'ptmono': ['PT Mono', 'ptmono'], - 'ubuntu': ['Ubuntu Mono', 'ubuntu'], - 'jetbrains' : ['JetBrains Mono', 'jetbrains'] - }, - 'sans': - {'droidsans': ['Droid Sans', 'droidsans'], - 'opensans': ['Open Sans', 'opensans'], - 'ptsans': ['PT Sans', 'ptsans'], - 'sourcesans': ['Source Sans Pro', 'sourcesans'], - 'robotosans': ['Roboto', 'robotosans'], - 'latosans': ['Lato', 'latosans'], - 'exosans': ['Exo_2', 'exosans'], - 'proxima': ['Proxima Nova', 'proximasans']}, - 'serif': - {'ptserif': ['PT Serif', 'ptserif'], - 'ebserif': ['EB Garamond', 'ebserif'], - 'loraserif': ['Lora', 'loraserif'], - 'merriserif': ['Merriweather', 'merriserif'], - 'crimsonserif': ['Crimson Text', 'crimsonserif'], - 'georgiaserif': ['Georgia', 'georgiaserif'], - 'neutonserif': ['Neuton', 'neutonserif'], - 'cardoserif': ['Cardo Serif', 'cardoserif'], - 'goudyserif': ['Goudy Serif', 'goudyserif']}} if get_all: return fonts if fontcode in list(fonts['mono']): From 29e0cf72006ee2629deeeed13783ae805fa47157 Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Thu, 13 Oct 2022 00:34:46 +0200 Subject: [PATCH 2/5] Add argcomplete to requirements.txt The module argcomplete is used to enable autocompletion on jt flags. --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 6c0c940..9f9a5ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ notebook>=5.6.0 ipython>=5.4.1 matplotlib>=1.4.3 lesscpy>=0.11.2 +argcomplete>=2.0.0 From 76fff2cc476a8ae18c36b9b2ae30cb42623cd9b1 Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Thu, 13 Oct 2022 00:36:14 +0200 Subject: [PATCH 3/5] Enable autocompletion for themes and fonts flags --- jupyterthemes/__init__.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/jupyterthemes/__init__.py b/jupyterthemes/__init__.py index 0f69837..8e3038c 100755 --- a/jupyterthemes/__init__.py +++ b/jupyterthemes/__init__.py @@ -1,9 +1,11 @@ import os -import sys from argparse import ArgumentParser +from collections import ChainMap from glob import glob + +import argcomplete + from . import stylefx -from . import jtplot # path to local site-packages/jupyterthemes package_dir = os.path.dirname(os.path.realpath(__file__)) @@ -125,6 +127,9 @@ def install_theme(theme=None, def main(): parser = ArgumentParser() + themes = get_themes() + themes.sort() + say_themes = "Available Themes: \n {}".format('\n '.join(themes)) parser.add_argument( '-l', "--list", @@ -135,13 +140,15 @@ def main(): "--theme", default=None, action='store', - help="theme name to install") + help="theme name to install", + choices=themes) parser.add_argument( '-f', "--monofont", action='store', default=None, - help='monospace code font') + help='monospace code font', + choices=stylefx.fonts['mono']) parser.add_argument( '-fs', "--monosize", @@ -153,7 +160,8 @@ def main(): "--nbfont", action='store', default=None, - help='notebook font') + help='notebook font', + choices=ChainMap(*stylefx.fonts.values())) parser.add_argument( '-nfs', "--nbfontsize", @@ -165,7 +173,8 @@ def main(): "--tcfont", action='store', default=None, - help='txtcell font') + help='txtcell font', + choices=ChainMap(*stylefx.fonts.values())) parser.add_argument( '-tfs', "--tcfontsize", @@ -286,10 +295,8 @@ def main(): action='store_true', help="keep customization: do not reset jupyter notebook custom.js") + argcomplete.autocomplete(parser) args = parser.parse_args() - themes = get_themes() - themes.sort() - say_themes = "Available Themes: \n {}".format('\n '.join(themes)) if args.reset: stylefx.reset_default(verbose=True) From a5d811e24d9e4356148f8c341cdea0dfc346f0c4 Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Thu, 13 Oct 2022 00:49:24 +0200 Subject: [PATCH 4/5] Add reference for tab completion --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d3e2170..e334842 100755 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ jt [-h] [-l] [-t THEME] [-f MONOFONT] [-fs MONOSIZE] [-nf NBFONT] [-cellw CELLWIDTH] [-lineh LINEHEIGHT] [-altp] [-altmd] [-altout] [-P] [-T] [-N] [-r] [-dfonts] ``` +Tab completion are available thanks to [argcomplete](https://kislyuk.github.io/argcomplete/#). Following the docs you can enable tab completion for your shell (bash, zsh, fish or tcsh). #### Description of Command Line options | cl options | arg | default | From e53eaa09af61770ed033074e7ebf308971bc1a6d Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Thu, 13 Oct 2022 01:11:00 +0200 Subject: [PATCH 5/5] Update setup.py Add argcomplete>=2.0.0 to install_requires --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7fe96ab..9e3272f 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ for fsub in fsubdirs]) datafiles[pkgname].extend(list(fontsdata)) -install_requires = ['jupyter_core', 'notebook>=5.6.0', 'ipython>=5.4.1', 'matplotlib>=1.4.3', 'lesscpy>=0.11.2'] +install_requires = ['jupyter_core', 'notebook>=5.6.0', 'ipython>=5.4.1', 'matplotlib>=1.4.3', 'lesscpy>=0.11.2', 'argcomplete>=2.0.0'] setup( name='jupyterthemes',