Skip to content

Commit

Permalink
Add configuratino for tui
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrogallo committed Feb 26, 2019
1 parent 49248f9 commit 178d36f
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 27 deletions.
9 changes: 9 additions & 0 deletions doc/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ A more complete example of a configuration file is the following
<span color='#ff00ff'> {doc.html_escape[author]}</span>
<yellow> ({doc.html_escape[year]})</yellow>
[tui]
editmode = vi
options_list.selected_margin_style = bg:ansigreen fg:ansired
options_list.unselected_margin_style =
# Define a lib
[papers]
dir = ~/Documents/papers
tui-editmode = emacs
tui-options_list.unselected_margin_style = bg:blue
# Define a lib for books
[books]
dir = ~/Documents/books
Expand Down
101 changes: 88 additions & 13 deletions papis/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""
General
*******
.. papis-config:: local-config-file
Name AND relative path of the local configuration file that papis
Expand Down Expand Up @@ -238,8 +235,8 @@
.. _add-command-options:
Add command options
^^^^^^^^^^^^^^^^^^^
``papis add`` options
^^^^^^^^^^^^^^^^^^^^^
.. papis-config:: ref-format
Expand Down Expand Up @@ -298,8 +295,8 @@
will fave the contrary effect, i.e., it will not open the attached files
before adding the document to the library.
Browse command options
^^^^^^^^^^^^^^^^^^^^^^
``papis browse`` options
^^^^^^^^^^^^^^^^^^^^^^^^
.. papis-config:: browse-key
Expand All @@ -316,8 +313,8 @@
.. _edit-command-options:
Edit command options
^^^^^^^^^^^^^^^^^^^^
``papis edit`` options
^^^^^^^^^^^^^^^^^^^^^^
.. papis-config:: notes-name
Expand Down Expand Up @@ -398,7 +395,7 @@
mark-opener-format = zathura -P {mark[value]}
Downloaders
===========
^^^^^^^^^^^
.. papis-config:: downloader-proxy
Expand All @@ -407,7 +404,7 @@
`link <http://docs.python-requests.org/en/master/user/advanced/#proxies>`_.
Databases
=========
^^^^^^^^^
.. papis-config:: default-query-string
Expand Down Expand Up @@ -462,8 +459,85 @@
`the documentation <https://whoosh.readthedocs.io/en/latest/schema.html/>`_
for more information.
Terminal user interface (picker)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
These options are for the terminal user interface (tui).
They are defined in the section ``tui`` which means that you can set them
in your configuration file globaly like
.. code:: ini
[tui]
status_line_format = "F1: Help"
...
or inside the library sections prepending a ``tui-``,
.. code:: ini
[papers]
tui-status_line_format = "Library papers"
...
.. papis-config:: status_line_format
:section: tui
This is the format of the string that appears on the bottom line in the
status line.
Right now there are only two variables defined:
- ``selected_index``
- ``number_of_documents``
Which are self-explanatory.
.. papis-config:: status_line_style
:section: tui
The style the status line should have.
Examples are ``fg:#ff00aa bg:black`` etc...
More information can be found
`here
<https://python-prompt-toolkit.readthedocs.io/en/master/pages/advanced_topics/styling.html/>`_
.
.. papis-config:: message_toolbar_style
:section: tui
The style of the message toolbar, this toolbar is the one
where messages of the ``echo`` command are rendered for instance.
.. papis-config:: options_list.selected_margin_style
:section: tui
Style of the margin of the selected document in the picker.
.. papis-config:: options_list.unselected_margin_style
:section: tui
Style of the margin of the unselected documents in the picker.
If you don't want any coloring for them you can just set this setting
to the empty string as such
::
tui-options_list.unselected_margin_style =
.. papis-config:: error_toolbar_style
:section: tui
The style for the error messages.
.. papis-config:: editmode
:section: tui
Whenever the user is typing text, one can use either
``emacs`` like keybindings or ``vi``. If this does not tell you
anything, you can just leave it as is.
Other
=====
^^^^^
.. papis-config:: citation-string
Expand Down Expand Up @@ -595,7 +669,6 @@ def get_default_opener():
"citation-string": "*",
'unique-document-keys': "['doi','ref','isbn','isbn10','url','doc_url']",

"tui-editmode": "emacs",
"downloader-proxy": None,
"bibtex-unicode": False,

Expand Down Expand Up @@ -638,12 +711,14 @@ def get_default_settings(section="", key=""):
global _DEFAULT_SETTINGS
# We use an OrderedDict so that the first entry will always be the general
# settings, also good for automatic documentation
import papis.tui
from collections import OrderedDict
if _DEFAULT_SETTINGS is None:
_DEFAULT_SETTINGS = OrderedDict()
_DEFAULT_SETTINGS.update({
get_general_settings_name(): general_settings,
})
_DEFAULT_SETTINGS.update(papis.tui.get_default_settings())
if not section and not key:
return _DEFAULT_SETTINGS
elif not section:
Expand Down
16 changes: 16 additions & 0 deletions papis/tui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
from papis.tui.app import Picker


def get_default_settings():
return dict(tui={
"status_line_format": (
"{selected_index}/{number_of_documents} " +
"F1:help " +
"Ctrl-l:redraw " +
"c-x:execute command "
),

"status_line_style": 'bg:ansiwhite fg:ansiblack',
'message_toolbar_style': 'bg:ansiyellow fg:ansiblack',
'options_list.selected_margin_style': 'bg:ansiblack fg:ansigreen',
'options_list.unselected_margin_style': 'bg:ansiwhite',
'error_toolbar_style': 'bg:ansired fg:ansiblack',

"editmode": "emacs",
})
36 changes: 22 additions & 14 deletions papis/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def __init__(
self.message_toolbar = MessageToolbar(style="class:message_toolbar")
self.error_toolbar = MessageToolbar(style="class:error_toolbar")
self.status_line = MessageToolbar(style="class:status_line")
self.status_line_format = papis.config.get(
'status_line_format', section="tui"
)

self.options_list = OptionsList(
options,
Expand Down Expand Up @@ -253,15 +256,25 @@ def __init__(
input=None,
output=None,
editing_mode=EditingMode.EMACS
if papis.config.get('tui-editmode') == 'emacs'
if papis.config.get('editmode', section='tui') == 'emacs'
else EditingMode.VI,
layout=self.layout,
style=Style.from_dict({
'options_list.selected_margin': 'bg:ansiblack fg:ansigreen',
'options_list.unselected_margin': 'bg:ansiwhite',
'error_toolbar': 'bg:ansired fg:ansiblack',
'message_toolbar': 'bg:ansiyellow fg:ansiblack',
'status_line': 'bg:ansiwhite fg:ansiblack',
'options_list.selected_margin': papis.config.get(
'options_list.selected_margin_style', section='tui'
),
'options_list.unselected_margin': papis.config.get(
'options_list.unselected_margin_style', section='tui'
),
'error_toolbar': papis.config.get(
'error_toolbar_style', section='tui'
),
'message_toolbar': papis.config.get(
'message_toolbar_style', section='tui'
),
'status_line': papis.config.get(
'status_line_style', section='tui'
),
}),
key_bindings=kb,
include_default_pygments_style=False,
Expand All @@ -274,14 +287,9 @@ def deselect(self):
self.options_list.current_index = None

def refresh_status_line(self):
self.status_line.text = (
"{0}/{1} "
"F1:help "
"Ctrl-l:redraw "
"c-x:execute command"
).format(
int(self.options_list.current_index) + 1,
len(self.options_list.options),
self.status_line.text = self.status_line_format.format(
selected_index=int(self.options_list.current_index) + 1,
number_of_documents=len(self.options_list.options),
)

def refresh(self, *args):
Expand Down

0 comments on commit 178d36f

Please sign in to comment.