/usr/lib/python3/dist-packages/plainbox/vendor/textland/image.py is in python3-plainbox 0.5.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | # This file is part of textland.
#
# Copyright 2014 Canonical Ltd.
# Written by:
# Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
# Sylvain Pineau <sylvain.pineau@canonical.com>
#
# Textland is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Textland 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 Textland. If not, see <http://www.gnu.org/licenses/>.
from array import array
from .bits import Cell, Size
# ANSI color index
(
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE,
BRIGHT_BLACK, BRIGHT_RED, BRIGHT_GREEN, BRIGHT_YELLOW, BRIGHT_BLUE,
BRIGHT_MAGENTA, BRIGHT_CYAN, BRIGHT_WHITE
) = range(16)
# Supported text styles.
NORMAL = 0 # Normal (default style)
REVERSE = 1 << 0 # Reverse background and foreground colors
UNDERLINE = 1 << 1 # Underline mode
class TextImage:
"""
A rectangular, mutable text image.
The image supports NORMAL, REVERSE and UNDERLINE as per-cell attributes,
the 8 colors described in the ANSI standard and the BOLD video attribute
to render the foreground colors as bright (aka light or intensified).
"""
def __init__(self, size: Size):
self.size = size
self.width = self.size.width
self.text_buffer = array('u')
self.text_buffer.extend(' ' * size.width * size.height)
self.attribute_buffer = array('H') # Unsigned short
self.attribute_buffer.extend([0] * size.width * size.height)
def put(self, x: int, y: int, c: str, pa: int) -> None:
"""
Put character *c* with attributes *pa* into cell at (*x*, *y*)
:param x:
X coordinate
:param y:
Y coordinate
:param c:
One character string
:param pa:
Packed attribute (up to uint16_t)
"""
assert 0 <= x < self.size.width
assert 0 <= y < self.size.height
offset = x + y * self.width
self.text_buffer[offset] = c
self.attribute_buffer[offset] = pa
def get(self, x: int, y: int) -> Cell:
"""
Get a cell from (*x*, *y*)
:param x:
X coordinate
:param y:
Y coordinate
:returns:
Cell(c, pa)
"""
offset = x + y * self.width
return Cell(self.text_buffer[offset], self.attribute_buffer[offset])
def print_frame(self) -> None:
text_buffer = self.text_buffer
width = self.size.width
height = self.size.height
print("/{}\\".format('=' * width))
for y in range(height):
line = text_buffer[y * width: (y + 1) * width].tounicode()
print("|{}|".format(line))
print("\\{}/".format('=' * width))
class TextAttributes:
def __init__(self):
self.fg = WHITE
self.bg = BLACK
self.style = NORMAL
def reset(self):
self.fg = WHITE
self.bg = BLACK
self.style = NORMAL
@property
def packed(self):
return ((self.fg & 15) << 8) + ((self.bg & 15) << 4) + (self.style & 3)
@staticmethod
def unpack(pa: int) -> (int, int, int):
"""
Unpack packed attributes into (fg, bg, style)
"""
fg = (pa >> 8) & 15
bg = (pa >> 4) & 15
style = pa & 3
return fg, bg, style
|