本文整理汇总了Python中console.Console.clear_line方法的典型用法代码示例。如果您正苦于以下问题:Python Console.clear_line方法的具体用法?Python Console.clear_line怎么用?Python Console.clear_line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类console.Console
的用法示例。
在下文中一共展示了Console.clear_line方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConsoleFormatter
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import clear_line [as 别名]
class ConsoleFormatter(object):
def __init__(self, stream, theme, tab=8, showgutter=True):
self._c = Console(stream)
self._theme = theme
self._tabstop = u' ' * tab
self._lineno = 1
self._showgutter = showgutter
self._gutter = (
Color(theme.gutter[u'foreground']),
Color(theme.gutter[u'background']),
Color(theme.gutter[u'divider'])
)
def start_document(self, name):
theme = self._theme.theme_for_scope(u'')
fg = Color(theme[u'foreground'])
bg = Color(theme[u'background'])
self._c.pset(fg=fg, bg=bg).clear_line()
self.gutter()
def end_document(self):
self._c.pop()
self._c.reset().write(u'\n')
def start_scope(self, name, off, line):
theme = self._theme.theme_for_scope(name)
fg = None
if u'foreground' in theme:
fg = Color(theme[u'foreground'])
bg = None
if u'background' in theme:
bg = Color(theme[u'background'])
self._c.pset(fg=fg, bg=bg)
def end_scope(self, off, line):
self._c.pop()
def characters(self, str):
last = 0
str = str.replace(u'\t', self._tabstop)
idx = str.find('\n', last)
while idx != -1:
self._c.write(str[last:idx+1])
self._c.clear_line()
self.gutter()
last = idx+1
idx = str.find(u'\n', last)
self._c.write(str[last:])
def gutter(self):
if self._showgutter == True:
self._c.pset(fg=self._gutter[0], bg=self._gutter[1])
self._c.write(u'%4u' % self._lineno).set(fg=self._gutter[2]).write(u'│')
self._c.pop().write(u' ')
self._lineno += 1
示例2: DebugFormatter
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import clear_line [as 别名]
class DebugFormatter(object):
def __init__(self, stream, tab=8, theme=None):
self._stream = stream
self._c = None
self._tabstop = u' ' * tab
self._content = u''
if theme is not None:
self._c = Console(sys.stdout)
self._theme = theme
self._lineno = 1
self._gutter = (
Color(theme.gutter[u'foreground']),
Color(theme.gutter[u'background']),
Color(theme.gutter[u'divider'])
)
@property
def content(self):
return self._content
def start_document(self, name):
if self._c is not None:
theme = self._theme.theme_for_scope(u'')
fg = Color(theme[u'foreground'])
bg = Color(theme[u'background'])
self._c.pset(fg=fg, bg=bg)
self._c.clear_line()
self.gutter()
self._c.write(u'@%s{' % name)
self._stream.write(u'@%s{' % name)
def end_document(self):
if self._c is not None:
self._c.write(u'}')
self._c.pop()
self._c.reset()
self._c.write(u'\n')
self._stream.write(u'}')
def start_scope(self, name, off, line):
if self._c is not None:
theme = self._theme.theme_for_scope(name)
fg = None
if u'foreground' in theme:
fg = Color(theme[u'foreground'])
bg = None
if u'background' in theme:
bg = Color(theme[u'background'])
self._c.pset(fg=fg, bg=bg)
self._c.write(u'@%s(%u,%u){' % (name, off, line))
self._stream.write(u'@%s(%u,%u){' % (name, off, line))
def end_scope(self, off, line):
if self._c is not None:
self._c.write(u'}(%u,%u)' % (off, line))
self._c.pop()
self._stream.write(u'}(%u,%u)' % (off, line))
def characters(self, str):
self._content += str
last = 0
str = str.replace(u'\t', self._tabstop)
idx = str.find('\n', last)
while idx != -1:
self._stream.write(str[last:idx+1])
if self._c is not None:
self._c.write(str[last:idx+1])
self._c.clear_line()
self.gutter()
last = idx+1
idx = str.find(u'\n', last)
self._stream.write(str[last:])
if self._c is not None:
self._c.write(str[last:])
def gutter(self):
self._c.pset(fg=self._gutter[0], bg=self._gutter[1])
self._c.write(u'%4u' % self._lineno).set(fg=self._gutter[2]).write(u'│')
self._c.pop().write(u' ')
self._lineno += 1