Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoMeyer441 committed Jun 29, 2022
2 parents c7b4c18 + e0f853b commit 1c28d04
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-python-compatibility.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: pre-commit checks
name: check Python 3.5 compatibility
on: [push, pull_request]
jobs:
pre-commit:
Expand Down
22 changes: 18 additions & 4 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,28 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v2
- name: Install pre-commit
run: pip install "pre-commit==2.13.0"
run: pip install "pre-commit==2.17.0"
- name: Run pre-commit checks
run: |
TMP_MSG_FILE="$(mktemp)" &&
git log -1 --pretty=%B > "${TMP_MSG_FILE}" &&
pre-commit run --all-files --color=always --hook-stage commit &&
pre-commit run --all-files --color=always --hook-stage commit-msg --commit-msg-filename "${TMP_MSG_FILE}" &&
pre-commit run --all-files --color=always --hook-stage post-commit || {
pre-commit run \
--all-files \
--color=always \
--show-diff-on-failure \
--hook-stage commit &&
pre-commit run \
--all-files \
--color=always \
--show-diff-on-failure \
--hook-stage commit-msg \
--commit-msg-filename "${TMP_MSG_FILE}" &&
pre-commit run \
--all-files \
--color=always \
--show-diff-on-failure \
--hook-stage post-commit ||
{
>&2 echo "pre-commit checks failed. Please consider installing pre-commit";
>&2 echo "hooks in your local Git clone by running \`make git-hooks-install\`.";
exit 1;
Expand Down
22 changes: 18 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ pre-commit:
stage: check
image: python:3
before_script:
- pip install "pre-commit==2.13.0"
- pip install "pre-commit==2.17.0"
script:
- TMP_MSG_FILE="$(mktemp)"
- git log -1 --pretty=%B > "${TMP_MSG_FILE}"
- pre-commit run --all-files --color=always --hook-stage commit &&
pre-commit run --all-files --color=always --hook-stage commit-msg --commit-msg-filename "${TMP_MSG_FILE}" &&
pre-commit run --all-files --color=always --hook-stage post-commit || {
- pre-commit run
--all-files
--color=always
--show-diff-on-failure
--hook-stage commit &&
pre-commit run
--all-files
--color=always
--show-diff-on-failure
--hook-stage commit-msg
--commit-msg-filename "${TMP_MSG_FILE}" &&
pre-commit run
--all-files
--color=always
--show-diff-on-failure
--hook-stage post-commit ||
{
>&2 echo "pre-commit checks failed. Please consider installing pre-commit";
>&2 echo "hooks in your local Git clone by running \`make git-hooks-install\`.";
exit 1;
Expand Down
36 changes: 18 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_stages: ['commit']
repos:
# pre-commit repo:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.1.0
hooks:
# general hooks:
- id: check-added-large-files # Prevent giant files from being committed
Expand All @@ -29,56 +29,56 @@ repos:
- id: requirements-txt-fixer # Sorts entries in requirements.txt and removes incorrect entry `pkg-resources==0.0.0`
# General repos:
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.3.5
rev: 2.4.0
hooks:
- id: editorconfig-checker
exclude_types: [markdown]
- repo: https://github.com/IngoMeyer441/detect-direct-checkins
rev: v0.1.1
rev: v0.1.2
hooks:
- id: detect-direct-checkins
args: ['--branch=master', '--allow-root']
- repo: https://github.com/jorisroovers/gitlint
rev: v0.15.1
rev: v0.17.0
hooks:
- id: gitlint
args: [
'--ignore=body-is-missing,title-must-not-contain-word',
'--msg-filename'
'--msg-filename',
]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.27.1
rev: v0.31.1
hooks:
- id: markdownlint
- repo: https://github.com/adrienverge/yamllint
rev: v1.26.1
rev: v1.26.3
hooks:
- id: yamllint
args: [
'--config-data={extends: default, rules: {indentation: {indent-sequences: consistent}, line-length: {max: 120}}}'
]
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.4.0
rev: 0.14.0
hooks:
- id: check-jsonschema
name: "Validate GitLab CI configuration"
name: 'Validate GitLab CI configuration'
files: ^\.gitlab-ci.yml
args: ["--schemafile", "https://json.schemastore.org/gitlab-ci"]
args: [
'--schemafile',
'https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json',
]
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.4.0
rev: 0.14.0
hooks:
- id: check-github-workflows
# Python specific repos:
- repo: https://github.com/psf/black
rev: 21.6b0
rev: 22.3.0
hooks:
- id: black
args: [
'--line-length=120',
'--target-version=py35',
]
args: ['--line-length=120']
- repo: https://github.com/PyCQA/isort
rev: 5.9.2
rev: 5.10.1
hooks:
- id: isort
args: [ # Arguments for `black` compatibility
Expand All @@ -90,7 +90,7 @@ repos:
'--ensure-newline-before-comments',
]
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
rev: 4.0.1
hooks:
- id: flake8
args: [
Expand Down
66 changes: 46 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,63 @@
PRECOMMIT_VERSION=2.13.0
PRECOMMIT_VERSION = 2.17.0

PRECOMMIT_ENV := $(shell git rev-parse --git-dir 2>/dev/null || echo ".")/.pre-commit_env

no-default:
@echo "There is no default target. Please choose one of the following targets: check, git-hooks-install"
@exit 1

check-git:
@if ! command -v git >/dev/null 2>&1; then \
>&2 echo "Please install Git first."; \
exit 1; \
fi
@if ! git rev-parse --git-dir >/dev/null 2>&1; then \
>&2 echo "You are not in a Git repository, but pre-commit requires this."; \
>&2 echo "Is this an unpacked source code archive?"; \
exit 1; \
fi

check-python:
@if ! command -v python3 >/dev/null 2>&1; then \
>&2 echo "Please install Python 3 first."; \
exit 1; \
fi;
fi
@if ! python3 -m venv --help >/dev/null 2>&1; then \
>&2 echo "Please install the Python 3 venv module."; \
exit 1; \
fi;
fi

check: check-python
install-pre-commit: check-git check-python
@if ! [ -d "$(PRECOMMIT_ENV)" ] || ! "$(PRECOMMIT_ENV)/bin/python" --version >/dev/null 2>&1; then \
echo "Installing pre-commit to \"$(PRECOMMIT_ENV)\"" && \
rm -rf "$(PRECOMMIT_ENV)" && \
python3 -m venv "$(PRECOMMIT_ENV)" && \
"$(PRECOMMIT_ENV)/bin/pip" install "pre-commit==$(PRECOMMIT_VERSION)" || exit; \
fi

check: install-pre-commit
@TMP_PRECOMMIT_DIR="$$(mktemp -d 2>/dev/null || mktemp -d -t 'tmp' 2>/dev/null)" && \
python3 -m venv "$${TMP_PRECOMMIT_DIR}" && \
"$${TMP_PRECOMMIT_DIR}/bin/pip" install "pre-commit==$(PRECOMMIT_VERSION)" && \
git log -1 --pretty=%B > "$${TMP_PRECOMMIT_DIR}/commit_msg" && \
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" run --all-files --hook-stage commit && \
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" run --all-files --hook-stage commit-msg \
"$(PRECOMMIT_ENV)/bin/pre-commit" run \
--all-files \
--show-diff-on-failure \
--hook-stage commit && \
"$(PRECOMMIT_ENV)/bin/pre-commit" run \
--all-files \
--show-diff-on-failure \
--hook-stage commit-msg \
--commit-msg-filename "$${TMP_PRECOMMIT_DIR}/commit_msg" && \
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" run --all-files --hook-stage post-commit && \
rm -rf "$${TMP_PRECOMMIT_DIR}"
"$(PRECOMMIT_ENV)/bin/pre-commit" run \
--all-files \
--show-diff-on-failure \
--hook-stage post-commit; \
RETURN_CODE="$$?"; \
rm -rf "$${TMP_PRECOMMIT_DIR}"; \
exit "$${RETURN_CODE}"

git-hooks-install: check-python
@TMP_PRECOMMIT_DIR="$$(mktemp -d 2>/dev/null || mktemp -d -t 'tmp' 2>/dev/null)" && \
python3 -m venv "$${TMP_PRECOMMIT_DIR}" && \
"$${TMP_PRECOMMIT_DIR}/bin/pip" install "pre-commit==$(PRECOMMIT_VERSION)" && \
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" install --hook-type pre-commit && \
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" install --hook-type commit-msg && \
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" install --hook-type post-commit && \
rm -rf "$${TMP_PRECOMMIT_DIR}"

.PHONY: no-default check-python check git-hooks-install
git-hooks-install: install-pre-commit
@"$(PRECOMMIT_ENV)/bin/pre-commit" install --hook-type pre-commit && \
"$(PRECOMMIT_ENV)/bin/pre-commit" install --hook-type commit-msg && \
"$(PRECOMMIT_ENV)/bin/pre-commit" install --hook-type post-commit

.PHONY: no-default check-git check-python check git-hooks-install
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,27 @@ Preview commands are allowed to generate [ANSI escape color codes](https://en.wi

![screenshot_preview_tmux_sessions](https://raw.githubusercontent.com/IngoMeyer441/simple-term-menu/master/preview_tmux_sessions.png)

### Skipping empty entries

Use the constructor parameter `skip_empty_entries` or the flag `--skip-empty-entries` to interpret an empty string value
in the menu entries as an empty menu entry (will be skipped when iterating over the entries). A `None` value is always
considered as an empty menu entry independently from the `skip_empty_entries` parameter.

```python
from simple_term_menu import TerminalMenu

def main(): # Or use `None` instead of `""`:
options = ["entry 1", "entry 2", "", "add", "edit"] # ["entry 1", "entry 2", None, "add", "edit"]
terminal_menu = TerminalMenu(options, skip_empty_entries=True) # TerminalMenu(options)
menu_entry_index = terminal_menu.show()
print(f"You have selected {options[menu_entry_index]}!")

if __name__ == "__main__":
main()
```

![screenshot_skip_empty_entries](https://raw.githubusercontent.com/IngoMeyer441/simple-term-menu/master/skip_empty_entries.png)

### Localization / Text modification

Use the constructor parameters
Expand All @@ -397,13 +418,16 @@ to modify the corresponding texts. Use the placeholder `{key}` for the search ke

Furthermore, the `TerminalMenu` constructor takes these additional parameters to change the menu behavior:

- `cycle_cursor`: A bool value which indicates if the menu cursor cycles when the end of the menu is reached. Defaults
to `True`.
- `clear_screen`: A bool value which indicates if the screen will be cleared before the menu is shown. Defaults to
`False`.
- `clear_menu_on_exit`: A bool value which indicates if the menu will be cleared after the `show` method. Defaults to
`True`.
- `clear_screen`: A bool value which indicates if the screen will be cleared before the menu is shown. Defaults to
`False`.
- `cursor_index`: The initially selected item index.
- `cycle_cursor`: A bool value which indicates if the menu cursor cycles when the end of the menu is reached. Defaults
to `True`.
- `quit_keys`: An iterable of keys which quit the terminal menu. Defaults to `("escape", "q")`.
- `raise_error_on_interrupt`: Set this to `True` to reraise Keyboard interrupts (by pressing `<Ctrl-c>`). Defaults to
`False`.
- `status_bar_below_preview`: Position the status bar below the preview window (default positioning is above).

### Command line program
Expand All @@ -421,8 +445,8 @@ usage: simple-term-menu [-h] [-s] [-X] [-l] [--cursor CURSOR]
[--multi-select-cursor-style MULTI_SELECT_CURSOR_STYLE]
[--multi-select-keys MULTI_SELECT_KEYS]
[--multi-select-no-select-on-accept]
[-p PREVIEW_COMMAND] [--no-preview-border]
[--preview-size PREVIEW_SIZE]
[--multi-select-empty-ok] [-p PREVIEW_COMMAND]
[--no-preview-border] [--preview-size PREVIEW_SIZE]
[--preview-title PREVIEW_TITLE]
[--search-highlight-style SEARCH_HIGHLIGHT_STYLE]
[--search-key SEARCH_KEY]
Expand All @@ -433,7 +457,8 @@ usage: simple-term-menu [-h] [-s] [-X] [-l] [--cursor CURSOR]
[--show-search-hint]
[--show-search-hint-text SHOW_SEARCH_HINT_TEXT]
[--show-shortcut-hints]
[--show-shortcut-hints-in-title] [-b STATUS_BAR] [-d]
[--show-shortcut-hints-in-title]
[--skip-empty-entries] [-b STATUS_BAR] [-d]
[--status-bar-style STATUS_BAR_STYLE] [--stdout]
[-t TITLE] [-V]
[-r PRESELECTED_ENTRIES | -R PRESELECTED_INDICES]
Expand All @@ -444,7 +469,7 @@ simple-term-menu creates simple interactive menus in the terminal and returns th
positional arguments:
entries the menu entries to show
optional arguments:
options:
-h, --help show this help message and exit
-s, --case-sensitive searches are case sensitive
-X, --no-clear-menu-on-exit
Expand Down Expand Up @@ -479,6 +504,9 @@ optional arguments:
do not select the currently highlighted menu item when
the accept key is pressed (it is still selected if no
other item was selected before)
--multi-select-empty-ok
when used together with --multi-select-no-select-on-
accept allows returning no selection at all
-p PREVIEW_COMMAND, --preview PREVIEW_COMMAND
Command to generate a preview for the selected menu
entry. "{}" can be used as placeholder for the menu
Expand Down Expand Up @@ -517,6 +545,8 @@ optional arguments:
show shortcut hints in the status bar
--show-shortcut-hints-in-title
show shortcut hints in the menu title
--skip-empty-entries Interpret an empty string in menu entries as an empty
menu entry
-b STATUS_BAR, --status-bar STATUS_BAR
status bar text
-d, --status-bar-below-preview
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ def finalize_options(self) -> None:
def run(self) -> None:
with TemporaryDirectory() as temp_dir:
subprocess.check_call(["python3", "-m", "venv", os.path.join(temp_dir, "env")])
subprocess.check_call(
[os.path.join(temp_dir, "env/bin/pip"), "install", "--upgrade", "pip", "setuptools", "wheel"]
)
subprocess.check_call([os.path.join(temp_dir, "env/bin/pip"), "install", "."])
subprocess.check_call([os.path.join(temp_dir, "env/bin/pip"), "install", "pyinstaller<4.4"])
subprocess.check_call([os.path.join(temp_dir, "env/bin/pip"), "install", "pyinstaller"])
with open(os.path.join(temp_dir, "entrypoint.py"), "w") as f:
f.write(
"""
Expand Down
Loading

0 comments on commit 1c28d04

Please sign in to comment.