def addline(self, y, string, attr):
"""
Displays a string on the screen. Handles truncation and borders.
"""
if y >= self.max_y:
return
# Display the left blank border.
self.addstr(
y=y,
x=0,
string=' ' * self.offset_x,
attr=curses.A_NORMAL,
)
# Remove trailing spaces so the truncate logic works correctly.
string = string.rstrip()
# Truncate the string if it is too long.
if self.offset_x + len(string) + self.offset_x > self.max_x:
string = string[:self.max_x - self.offset_x - self.offset_x - 2] + '..'
# Add whitespace between the end of the string and the edge of the
# screen. This is required when scrolling, to blank out characters
# from other lines that had been displayed here previously.
string += ' ' * (self.max_x - self.offset_x - len(string) - self.offset_x)
# Display the string.
self.addstr(
y=y,
x=self.offset_x,
string=string,
attr=attr,
)
# Display the right blank border.
self.addstr(
y=y,
x=self.max_x - self.offset_x,
string=' ' * self.offset_x,
attr=curses.A_NORMAL,
)
评论列表
文章目录