Handles the case where self.file is None

Fixes #46
This commit is contained in:
Georgios Verigakis
2018-03-13 15:53:27 +02:00
parent 292a031c4b
commit a83f91f4b8

View File

@@ -28,14 +28,14 @@ class WriteMixin(object):
if message:
self.message = message
if self.file.isatty():
if self.file and self.file.isatty():
if self.hide_cursor:
print(HIDE_CURSOR, end='', file=self.file)
print(self.message, end='', file=self.file)
self.file.flush()
def write(self, s):
if self.file.isatty():
if self.file and self.file.isatty():
b = '\b' * self._width
c = s.ljust(self._width)
print(b + c, end='', file=self.file)
@@ -43,7 +43,7 @@ class WriteMixin(object):
self.file.flush()
def finish(self):
if self.file.isatty() and self.hide_cursor:
if self.file and self.file.isatty() and self.hide_cursor:
print(SHOW_CURSOR, end='', file=self.file)
@@ -55,21 +55,21 @@ class WritelnMixin(object):
if message:
self.message = message
if self.file.isatty() and self.hide_cursor:
if self.file and self.file.isatty() and self.hide_cursor:
print(HIDE_CURSOR, end='', file=self.file)
def clearln(self):
if self.file.isatty():
if self.file and self.file.isatty():
print('\r\x1b[K', end='', file=self.file)
def writeln(self, line):
if self.file.isatty():
if self.file and self.file.isatty():
self.clearln()
print(line, end='', file=self.file)
self.file.flush()
def finish(self):
if self.file.isatty():
if self.file and self.file.isatty():
print(file=self.file)
if self.hide_cursor:
print(SHOW_CURSOR, end='', file=self.file)