Skip to content

Commit

Permalink
Extract key mappings for configuration (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
cielong committed Nov 16, 2020
1 parent e44f728 commit d7faf98
Show file tree
Hide file tree
Showing 47 changed files with 569 additions and 144 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.0-beta] - 2020-11-15

### Added

- Support configuration
- Add modes "emacs" and "vim" as predefined key mappings

### Fixed

- Focus line jumping around when moving up / below

## [0.1.0-alpha.3] - 2020-10-18

Expand Down Expand Up @@ -35,7 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial commit with pyfx

[unreleased]: https://github.com/cielong/pyfx/compare/v0.1.0-alpha.3...HEAD
[unreleased]: https://github.com/cielong/pyfx/compare/v0.1.0-beta...HEAD
[0.1.0-beta]: https://github.com/cielong/pyfx/compare/v0.1.0-alpha.3...v0.1.0-beta
[0.1.0-alpha.3]: https://github.com/cielong/pyfx/compare/v0.1.0-alpha.2...v0.1.0-alpha.3
[0.1.0-alpha.2]: https://github.com/cielong/pyfx/compare/v0.1.0-alpha.1...v0.1.0-alpha.2
[0.1.0-alpha.1]: https://github.com/cielong/pyfx/compare/v0.1.0-alpha...v0.1.0-alpha.1
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ include tox.ini

# include Trave CI config
include .travis.yml

# include pyfx config
include src/pyfx/config/*.yml
include src/pyfx/view/keymapper/modes/*.yml
4 changes: 4 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ sphinx-click = "*"
pytest-cov = "*"
loguru = "*"
jsonpath-ng = "*"
yamale = "*"
dacite = "*"
dataclasses = "*"
first = "*"

[requires]
python_version = "3.8"
95 changes: 71 additions & 24 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 61 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ from pyfx import Controller
Controller().run_with_data(data)
```
#### Import *pyfx*'s Native JSON Library and Integrate with Your Own TUI
You can also import *pyfx* native JSON lib to integrate it into your own urwid TUI, e.g. [view_window.py](https://github.com/cielong/pyfx/blob/master/src/pyfx/view/components/view_window.py).
You can also import *pyfx* native JSON lib to integrate it into your own urwid TUI, e.g. [json_browser.py](https://github.com/cielong/pyfx/blob/master/src/pyfx/view/components/json_browser/json_browser.py).
```python
from pyfx.view.json_lib import JSONListBox, JSONListWalker, NodeFactory

Expand All @@ -55,20 +55,71 @@ listbox = JSONListBox(JSONListWalker(top_node))
# use listbox in your own TUI
...
```
## Configuration
*pyfx* can be configured using YAML, the config file is either passed directly through CLI option or automatically
loaded in predefined config folderq.

### Key Mappings
If *pyfx* is invoked without `-c / --config` option, it will search config file in with the following order:
1. ~/.config/pyfx/config.yml
2. PYTHON_DIR/site-packages/pyfx/config/config.yml

### Predefined Key Mappings
Key mapping is configured with the following configuration schema
```
keymap:
mode: string, accepted_options = ["basic" (The default) | "emacs" | "vim"]
```
#### Basic Mode
| Key | Function |
|------------------|---------------------------------------------------|
| **Main Window** |
| q | exit pyfx |
| **View Window** |
| q | exit pyfx (except in Query Bar) |
| **JSON Browser** |
| up | move cursor up one line |
| down | move cursor down one line |
| enter | toggle expansion |
| up/ctrl p | move cursor up one line |
| down/ctrl n | move cursor down one line |
| **Query Window** |
| . | enter query window (used to input JSONPath query) |
| enter | apply JSONPath query and switch to View Window |
| esc | apply JSONPath query and exit Query Window |
| **Query Bar** |
| enter | apply JSONPath query and switch to JSON Browser |
| esc | cancel query and restore to state before query |

#### Emacs Mode
To enable, add the following configuration in your config file:
```yaml
keymap:
mode: "emacs"
```
##### Mapped Keys
| Key | Function |
|------------------|---------------------------------------------------|
| q | exit pyfx (except in Query Bar) |
| **JSON Browser** |
| up / ctrl p | move cursor up one line |
| down / ctrl n | move cursor down one line |
| enter | toggle expansion |
| . / meta x | enter query window (used to input JSONPath query) |
| **Query Bar** |
| enter | apply JSONPath query and switch to JSON Browser |
| ctrl g | cancel query and restore to state before query |

#### Vim Mode
To enable, add the following configuration in your config file:
```yaml
keymap:
mode: "vim"
```
##### Mapped Keys
| Key | Function |
|------------------|---------------------------------------------------|
| q | exit pyfx (except in Query Bar) |
| **JSON Browser** |
| up / k | move cursor up one line |
| down / j | move cursor down one line |
| enter | toggle expansion |
| . / : | enter query window (used to input JSONPath query) |
| **Query Bar** |
| enter | apply JSONPath query and switch to JSON Browser |
| esc | cancel query and restore to state before query |


## Full Documentation
Please visit [Documentation](https://python-fx.readthedocs.io/en/latest/)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0-alpha.3
0.1.0-beta
4 changes: 4 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
urwid==2.1.2
loguru==0.5.3
yamale==3.0.4
dataclasses==0.6
dacite==1.5.1
first==2.0.2
14 changes: 10 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

here = pathlib.Path(__file__).parent.resolve()

# Get the version from the VERSION file
# get the version from the VERSION file
version = (here / 'VERSION').read_text(encoding='utf-8')

# Get the long description from the README file
# get the long description from the README file
long_description = (here / 'README.md').read_text(encoding='utf-8')

setup(
Expand All @@ -27,13 +27,19 @@
keywords="fx, pyfx, json viewer, tui",
packages=find_packages('src'),
package_dir={'': 'src'},
package_data={'pyfx': ['config/*.yml', 'view/keymapper/modes/*.yml']},
include_package_data=True,
py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
install_requires=[
'click',
'urwid',
'overrides',
'jsonpath-ng',
'loguru'
'loguru',
'yamale',
'dataclasses',
'dacite',
'first'
],
setup_requires=[
'pytest-runner',
Expand All @@ -42,7 +48,7 @@
"console_scripts": ["pyfx=pyfx.cli:main"]
},
classifiers=[
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3 :: Only",
"Environment :: Console",
"Operating System :: POSIX",
Expand Down
Loading

0 comments on commit d7faf98

Please sign in to comment.