scylla-cqlsh 6.0.29__cp310-cp310-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cqlshlib/displaying.py ADDED
@@ -0,0 +1,128 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from collections import defaultdict
18
+
19
+ RED = '\033[0;1;31m'
20
+ GREEN = '\033[0;1;32m'
21
+ YELLOW = '\033[0;1;33m'
22
+ BLUE = '\033[0;1;34m'
23
+ MAGENTA = '\033[0;1;35m'
24
+ CYAN = '\033[0;1;36m'
25
+ WHITE = '\033[0;1;37m'
26
+ DARK_MAGENTA = '\033[0;35m'
27
+ ANSI_RESET = '\033[0m'
28
+
29
+
30
+ def colorme(bval, colormap, colorkey):
31
+ if colormap is NO_COLOR_MAP:
32
+ return bval
33
+ if colormap is None:
34
+ colormap = DEFAULT_VALUE_COLORS
35
+ return FormattedValue(bval, colormap[colorkey] + bval + colormap['reset'])
36
+
37
+
38
+ def get_str(val):
39
+ if isinstance(val, FormattedValue):
40
+ return val.strval
41
+ return val
42
+
43
+
44
+ class FormattedValue:
45
+
46
+ def __init__(self, strval, coloredval=None, displaywidth=None):
47
+ self.strval = strval
48
+ if coloredval is None:
49
+ coloredval = strval
50
+ self.coloredval = coloredval
51
+ if displaywidth is None:
52
+ displaywidth = len(strval)
53
+ # displaywidth is useful for display of special unicode characters
54
+ # with
55
+ self.displaywidth = displaywidth
56
+
57
+ def __len__(self):
58
+ return len(self.strval)
59
+
60
+ def _pad(self, width, fill=' '):
61
+ if width > self.displaywidth:
62
+ return fill * (width - self.displaywidth)
63
+ else:
64
+ return ''
65
+
66
+ def ljust(self, width, fill=' ', color=False):
67
+ """
68
+ Similar to self.strval.ljust(width), but takes expected terminal
69
+ display width into account for special characters, and does not
70
+ take color escape codes into account.
71
+ """
72
+ if color:
73
+ return self.color_ljust(width, fill=fill)
74
+ return self.strval + self._pad(width, fill)
75
+
76
+ def rjust(self, width, fill=' ', color=False):
77
+ """
78
+ Similar to self.strval.rjust(width), but takes expected terminal
79
+ display width into account for special characters, and does not
80
+ take color escape codes into account.
81
+ """
82
+ if color:
83
+ return self.color_rjust(width, fill=fill)
84
+ return self._pad(width, fill) + self.strval
85
+
86
+ def color_rjust(self, width, fill=' '):
87
+ """
88
+ Similar to self.rjust(width), but uses this value's colored
89
+ representation, and does not take color escape codes into account
90
+ in determining width.
91
+ """
92
+ return self._pad(width, fill) + self.coloredval
93
+
94
+ def color_ljust(self, width, fill=' '):
95
+ """
96
+ Similar to self.ljust(width), but uses this value's colored
97
+ representation, and does not take color escape codes into account
98
+ in determining width.
99
+ """
100
+ return self.coloredval + self._pad(width, fill)
101
+
102
+
103
+ DEFAULT_VALUE_COLORS = dict(
104
+ default=YELLOW,
105
+ text=YELLOW,
106
+ error=RED,
107
+ blob=DARK_MAGENTA,
108
+ timestamp=GREEN,
109
+ date=GREEN,
110
+ time=GREEN,
111
+ int=GREEN,
112
+ float=GREEN,
113
+ decimal=GREEN,
114
+ inet=GREEN,
115
+ boolean=GREEN,
116
+ uuid=GREEN,
117
+ duration=GREEN,
118
+ collection=BLUE,
119
+ reset=ANSI_RESET,
120
+ )
121
+
122
+ COLUMN_NAME_COLORS = defaultdict(lambda: MAGENTA,
123
+ error=RED,
124
+ blob=DARK_MAGENTA,
125
+ reset=ANSI_RESET,
126
+ )
127
+
128
+ NO_COLOR_MAP = dict()