summaryrefslogtreecommitdiff
path: root/scripts/utils.py
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2014-09-18 07:44:04 +0200
committerFlorian Bruhin <git@the-compiler.org>2014-09-18 08:31:36 +0200
commitc9a24f32f56dc1dc5e1eb29c593b2daac6a83286 (patch)
tree86ab1a363e0cbbc536dfe00d1d677a0228585754 /scripts/utils.py
parent0ce54ec1fcef6b85fd89dc7c513cafced4bcc1e8 (diff)
downloadqutebrowser-c9a24f32f56dc1dc5e1eb29c593b2daac6a83286.tar.gz
qutebrowser-c9a24f32f56dc1dc5e1eb29c593b2daac6a83286.zip
Use new utils module for colors in asciidoc2html.
Diffstat (limited to 'scripts/utils.py')
-rw-r--r--scripts/utils.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/scripts/utils.py b/scripts/utils.py
new file mode 100644
index 000000000..503b7b39d
--- /dev/null
+++ b/scripts/utils.py
@@ -0,0 +1,71 @@
+#!/usr/bin/python3 # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
+
+# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
+
+# This file is part of qutebrowser.
+#
+# qutebrowser is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# qutebrowser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
+
+"""Utility functions for scripts."""
+
+
+use_color = True
+
+
+fg_colors = {
+ 'black': 30,
+ 'red': 31,
+ 'green': 32,
+ 'yellow': 33,
+ 'blue': 34,
+ 'magenta': 35,
+ 'cyan': 36,
+ 'white': 37,
+ 'reset': 39,
+}
+
+
+bg_colors = {name: col + 10 for name, col in fg_colors.items()}
+
+
+term_attributes = {
+ 'bright': 1,
+ 'dim': 2,
+ 'normal': 22,
+ 'reset': 0,
+}
+
+
+def _esc(code):
+ return '\033[{}m'.format(code)
+
+
+def print_col(text, color):
+ """Print a colorized text."""
+ if use_color:
+ fg = _esc(fg_colors[color.lower()])
+ reset = _esc(fg_colors['reset'])
+ print(''.join([fg, text, reset]))
+ else:
+ print(text)
+
+
+def print_bold(text):
+ """Print a bold text."""
+ if use_color:
+ bold = _esc(term_attributes['bright'])
+ reset = _esc(term_attributes['reset'])
+ print(''.join([bold, text, reset]))
+ else:
+ print(text)