Skip to content

Commit

Permalink
Improve visual representation of SQL statements
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
chaudum committed Sep 25, 2019
1 parent a514504 commit 9a7af00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions crate/crash/repl.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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',
}


Expand Down Expand Up @@ -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='[](){}'),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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'
Expand Down

0 comments on commit 9a7af00

Please sign in to comment.