summaryrefslogtreecommitdiff
path: root/lib/outputmanager.py
blob: d9d4af1a4fd399e44ad0b3f1743b1c57585f6061 (plain)
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
#!/usr/bin/python3
import sys

class OutputManager:
    def __init__(self):
        
        self.echo_output = True

    def line_break(self):
        if self.echo_output:
            sys.stdout.write('\n')
            sys.stdout.flush()

        return self

    def error(self, string):
        if self.echo_output:
            self._erase_line()
            string = '[-] ' + string
            self.last_line_length = len(string)

            sys.stdout.write(string)
            sys.stdout.flush()

        return self

    def normal(self, string):
        if self.echo_output:
            self._erase_line()
            self.last_line_length = len(string)
            sys.stdout.write(string)
            sys.stdout.flush()

        return self

    def _erase_line(self):
        sys.stdout.write('\r' + ' ' * self.last_line_length + '\r')
        return self

        
    
nihil fit ex nihilo