[](https://travis-ci.org/chhsiao90/gviewer)
[](https://coveralls.io/github/chhsiao90/gviewer?branch=master)
**Simple, Light Weight, Powerful**
GViewer is a terminal UI library that depends on [urwid](https://github.com/urwid/urwid) simplified writing a tui based reporting system.
You could write a powerful terminal UI that display and operate with data as you want with just less and less code.
## Installation
```shell
pip install gviewer
```
## Run Example
There are some example in examples that provide some use cases.
You could see and run the examples.
```shell
python examples/panama.py
```
## Usage
### Data Store
####StaticDataStore
Used for static data list, like log file
Initiate with a list of eny type of content
The content will transfer to the your defined displayer later for display
```python
from gviewer import StaticDataStore
data_store = StaticDataStore(data)
```
#### AsyncDataStore
Used for asynchronous data list, like subscribe an [zeromq](http://zeromq.org/) publisher
```python
def register_func(on_message):
some_listener.on_message(on_message)
data_store = AsyncDataStore(register_func)
```
### Displayer
Defined how you display your data from Data Store to summary/details
```python
from gviewer import BaseDisplayer, View, Group, PropsGroup, Text, Prop
class MyDisplayer(BaseDisplayer):
def to_summary(self, message):
"""
return a str or text markup
reference: http://urwid.org/manual/displayattributes.html#text-markup
"""
return message["summary"]
def get_views(self):
"""return an array of tuple that contains view title and a function that transform message to detail"""
return [
("view1", self.view1),
("view2", self.view2),
]
def view1(self, message):
"""return groups"""
return View(
[Group("title", [Text(m) for m in message["view1"]])]
)
def view2(self, message):
"""return groups"""
return View(
[PropsGroup("title", [Prop(p[0], p[1]) for p in message["view2"]])]
)
```
### GViewer
Main class to start the tui
The constructor accept any of urwid.MainLoop arguments to intiate with custom config
```python
from gviewer import GViewer, DisplayerContext
context = DisplayerContext(data_store, displayer)
viewer = GViewer(context)
viewer.start()
```
## Advanced Usage
### Summary Actions
Bind function to specific key to apply customize action, ex: export
```python
from gviewer import GViewer, DisplayerContext
def custom_export(controller, message, widget, *args, **kwargs):
with open("export", "w") as f:
f.write(str(message))
controller.notify("file is export")
context = DisplayerContext(data_store, displayer, actions=Actions([("a", "Custom export", custom_export)]))
viewer = GViewer(context)
```
### View Actions
Bind function to specific key to apply customize action, ex: export
```python
from gviewer import View, BaseDisplayer
class MyDisplayer(BaseDisplayer):
def get_views(self):
return [("view", self.view)]
def view(self, message):
return View([], actions=Actions([("a", "Custom export", self.custom_export)]))
def custom_export(controller, message, *args, **kwargs):
with open("export", "w") as f:
f.write(str(message))
controller.notify("file is export")
```
## Built-in actions
### Summary
- /: search
- g: top
- G: bottom
- x: clear current item
- X: clear all items
- q: quit
- ?: help
### Detail
- /: search
- tab: next view
- shift+tab: prev view
- n: search next result
- N: search previous result
- e: export current content to file
- q: quit
- ?: help
## Contribution
Please feel free to create issue or create PR
Metadata
Release files for gviewer 3.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gviewer-3.0.6.tar.gz | 22.6 kB | Without provenance | Details for gviewer-3.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gviewer-3.0.6-py2-none-any.whl | Python 2 | none | any | Details for gviewer-3.0.6-py2-none-any.whl |
Total release size: 59.7 kB
Release files / gviewer-3.0.6.tar.gz
| Download URL | gviewer-3.0.6.tar.gz |
|---|---|
| Size | 22.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac0b059f8b8406c32108287d61dd53bedeb0d33e31614ca7bbc845b803c333a4
|
|
BLAKE2b-256 checksum How to use checksums |
1b94d8ed9d1329a285ce362c5294c9ebf1c3efdeeb99f651688156836e6c29d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / gviewer-3.0.6-py2-none-any.whl
| Download URL | gviewer-3.0.6-py2-none-any.whl |
|---|---|
| Size | 37.1 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
58c871486ec10cf28a7017a8cbff2bf5b597f2804cafd2ebe342cc1c29c32a79
|
|
BLAKE2b-256 checksum How to use checksums |
e9cdbf9d66080937ad4aeae5b4eb2704521a3bd29e92627bde6e691e7fb5bcc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for gviewer 3.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.