mirror of
https://github.com/dbcli/pgcli.git
synced 2024-10-06 10:17:15 +03:00
Merge pull request #834 from dbcli/fraoustin/colors_of_table
Add feature Color of table.
This commit is contained in:
commit
0feffcb778
@ -7,7 +7,7 @@ Features:
|
|||||||
* Change ``\h`` format string in prompt to only return the first part of the hostname,
|
* Change ``\h`` format string in prompt to only return the first part of the hostname,
|
||||||
up to the first '.' character. Add ``\H`` that returns the entire hostname (#858).
|
up to the first '.' character. Add ``\H`` that returns the entire hostname (#858).
|
||||||
(Thanks: `Andrew Kuchling`_)
|
(Thanks: `Andrew Kuchling`_)
|
||||||
|
* Add Color of table by parameter. The color of table is function of syntax style
|
||||||
|
|
||||||
Internal changes:
|
Internal changes:
|
||||||
-----------------
|
-----------------
|
||||||
|
@ -42,7 +42,7 @@ from pgspecial.main import (PGSpecial, NO_QUERY, PAGER_OFF)
|
|||||||
import pgspecial as special
|
import pgspecial as special
|
||||||
from .pgcompleter import PGCompleter
|
from .pgcompleter import PGCompleter
|
||||||
from .pgtoolbar import create_toolbar_tokens_func
|
from .pgtoolbar import create_toolbar_tokens_func
|
||||||
from .pgstyle import style_factory
|
from .pgstyle import style_factory, style_factory_output
|
||||||
from .pgexecute import PGExecute
|
from .pgexecute import PGExecute
|
||||||
from .pgbuffer import PGBuffer
|
from .pgbuffer import PGBuffer
|
||||||
from .completion_refresher import CompletionRefresher
|
from .completion_refresher import CompletionRefresher
|
||||||
@ -83,10 +83,10 @@ MetaQuery.__new__.__defaults__ = ('', False, 0, False, False, False, False)
|
|||||||
|
|
||||||
OutputSettings = namedtuple(
|
OutputSettings = namedtuple(
|
||||||
'OutputSettings',
|
'OutputSettings',
|
||||||
'table_format dcmlfmt floatfmt missingval expanded max_width case_function'
|
'table_format dcmlfmt floatfmt missingval expanded max_width case_function style_output'
|
||||||
)
|
)
|
||||||
OutputSettings.__new__.__defaults__ = (
|
OutputSettings.__new__.__defaults__ = (
|
||||||
None, None, None, '<null>', False, None, lambda x: x
|
None, None, None, '<null>', False, None, lambda x: x, None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -165,6 +165,9 @@ class PGCli(object):
|
|||||||
self.pgspecial.pset_pager(self.config['main'].as_bool(
|
self.pgspecial.pset_pager(self.config['main'].as_bool(
|
||||||
'enable_pager') and "on" or "off")
|
'enable_pager') and "on" or "off")
|
||||||
|
|
||||||
|
self.style_output = style_factory_output(
|
||||||
|
self.syntax_style, c['colors'])
|
||||||
|
|
||||||
self.now = dt.datetime.today()
|
self.now = dt.datetime.today()
|
||||||
|
|
||||||
self.completion_refresher = CompletionRefresher()
|
self.completion_refresher = CompletionRefresher()
|
||||||
@ -707,7 +710,8 @@ class PGCli(object):
|
|||||||
case_function=(
|
case_function=(
|
||||||
self.completer.case if self.settings['case_column_headers']
|
self.completer.case if self.settings['case_column_headers']
|
||||||
else lambda x: x
|
else lambda x: x
|
||||||
)
|
),
|
||||||
|
style_output=self.style_output
|
||||||
)
|
)
|
||||||
formatted = format_output(title, cur, headers, status, settings)
|
formatted = format_output(title, cur, headers, status, settings)
|
||||||
|
|
||||||
@ -1066,7 +1070,8 @@ def format_output(title, cur, headers, status, settings):
|
|||||||
'float_format': settings.floatfmt,
|
'float_format': settings.floatfmt,
|
||||||
'preprocessors': (format_numbers, format_arrays),
|
'preprocessors': (format_numbers, format_arrays),
|
||||||
'disable_numparse': True,
|
'disable_numparse': True,
|
||||||
'preserve_whitespace': True
|
'preserve_whitespace': True,
|
||||||
|
'style': settings.style_output
|
||||||
}
|
}
|
||||||
if not settings.floatfmt:
|
if not settings.floatfmt:
|
||||||
output_kwargs['preprocessors'] = (align_decimals, )
|
output_kwargs['preprocessors'] = (align_decimals, )
|
||||||
|
@ -158,6 +158,12 @@ Token.Toolbar.Arg.Text = 'nobold'
|
|||||||
Token.Toolbar.Transaction.Valid = 'bg:#222222 #00ff5f bold'
|
Token.Toolbar.Transaction.Valid = 'bg:#222222 #00ff5f bold'
|
||||||
Token.Toolbar.Transaction.Failed = 'bg:#222222 #ff005f bold'
|
Token.Toolbar.Transaction.Failed = 'bg:#222222 #ff005f bold'
|
||||||
|
|
||||||
|
# color of table
|
||||||
|
# you can use token or custom colors
|
||||||
|
Token.Output.Header = "#00ff5f bold"
|
||||||
|
Token.Output.OddRow = ""
|
||||||
|
Token.Output.EvenRow = ""
|
||||||
|
|
||||||
# Named queries are queries you can execute by name.
|
# Named queries are queries you can execute by name.
|
||||||
[named queries]
|
[named queries]
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ from pygments.util import ClassNotFound
|
|||||||
from prompt_toolkit.styles import PygmentsStyle
|
from prompt_toolkit.styles import PygmentsStyle
|
||||||
import pygments.styles
|
import pygments.styles
|
||||||
|
|
||||||
|
from pygments.style import Style
|
||||||
|
|
||||||
def style_factory(name, cli_style):
|
def style_factory(name, cli_style):
|
||||||
try:
|
try:
|
||||||
@ -10,8 +11,34 @@ def style_factory(name, cli_style):
|
|||||||
except ClassNotFound:
|
except ClassNotFound:
|
||||||
style = pygments.styles.get_style_by_name('native')
|
style = pygments.styles.get_style_by_name('native')
|
||||||
|
|
||||||
custom_styles = dict([(string_to_tokentype(x), y)
|
custom_styles = {}
|
||||||
for x, y in cli_style.items()])
|
for token in cli_style:
|
||||||
|
try:
|
||||||
|
custom_styles[string_to_tokentype(
|
||||||
|
token)] = style.styles[string_to_tokentype(cli_style[token])]
|
||||||
|
except AttributeError as err:
|
||||||
|
custom_styles[string_to_tokentype(token)] = cli_style[token]
|
||||||
|
|
||||||
return PygmentsStyle.from_defaults(style_dict=custom_styles,
|
return PygmentsStyle.from_defaults(style_dict=custom_styles,
|
||||||
pygments_style_cls=style)
|
pygments_style_cls=style)
|
||||||
|
|
||||||
|
|
||||||
|
def style_factory_output(name, cli_style):
|
||||||
|
try:
|
||||||
|
style = pygments.styles.get_style_by_name(name).styles
|
||||||
|
except ClassNotFound:
|
||||||
|
style = pygments.styles.get_style_by_name('native').styles
|
||||||
|
|
||||||
|
for token in cli_style:
|
||||||
|
try:
|
||||||
|
style.update({string_to_tokentype(
|
||||||
|
token): style[string_to_tokentype(cli_style[token])], })
|
||||||
|
except AttributeError as err:
|
||||||
|
style.update(
|
||||||
|
{string_to_tokentype(token): cli_style[token], })
|
||||||
|
|
||||||
|
class OutputStyle(pygments.style.Style):
|
||||||
|
default_style = ""
|
||||||
|
styles = style
|
||||||
|
|
||||||
|
return OutputStyle
|
||||||
|
Loading…
Reference in New Issue
Block a user