From 9a7af00cfc794433d544303e2b45f83c07b203c5 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Tue, 17 Sep 2019 20:45:36 +0200 Subject: [PATCH] Improve visual representation of SQL statements This commit changes the lexer for tokenizing the user input from the generic SqlLexer to the more specific PostgresLexer. Additionally the color scheme has been changed from a custom on to "terminal style", meaning that it will pick up the colors of the terminal emulator (http://pygments.org/docs/styles/#ansiterminalstyle). --- crate/crash/repl.py | 25 +++++++++++++------------ setup.py | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crate/crash/repl.py b/crate/crash/repl.py index 4b5c6aa6..b88c3244 100644 --- a/crate/crash/repl.py +++ b/crate/crash/repl.py @@ -23,15 +23,15 @@ import os import re -from pygments.lexers.sql import SqlLexer +from pygments.lexers.sql import PostgresLexer from pygments.style import Style from prompt_toolkit.output.defaults import get_default_output from prompt_toolkit.styles.pygments import style_from_pygments_cls from pygments.token import (Keyword, Comment, Operator, + Name, Number, - Literal, String, Error, Token) @@ -74,16 +74,17 @@ def _get_editing_mode(): class CrateStyle(Style): - default_style = "noinherit" + default_style = "" styles = { - Keyword: 'bold #4b95a3', - Comment: '#757265', - Operator: '#e83131', - Number: '#be61ff', - Literal: '#ae81ff', - String: '#f4a33d', - Error: '#ff3300', - Token.Toolbar.Status.Key: '#4b95a3', + Keyword: 'bold ansibrightblue', + Comment: 'ansigray', + Operator: 'ansibrightred', + Name.Builtin: 'ansiblue', + Number: 'ansimagenta', + String: 'ansiyellow', + String.Single: 'ansibrightgreen', + Error: 'bold ansired', + Token.Toolbar.Status.Key: 'ansiblue', } @@ -316,7 +317,7 @@ def loop(cmd, history_file): layout = create_layout( buffer=buf, multiline=True, - lexer=SqlLexer, + lexer=PostgresLexer, extra_input_processors=[ ConditionalProcessor( processor=HighlightMatchingBracketProcessor(chars='[](){}'), diff --git a/setup.py b/setup.py index da775a7a..dcacf8b4 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ requirements = [ 'colorama', - 'Pygments>=2.0', + 'Pygments>=2.4', 'crate>=0.22.0', 'appdirs>=1.2,<2.0', 'prompt-toolkit>=2.0,<3.0'