• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 7171266103

11 Dec 2023 05:41PM UTC coverage: 74.638% (+0.1%) from 74.499%
7171266103

push

github

Arusekk
term: hotfix

4564 of 7217 branches covered (0.0%)

12834 of 17195 relevant lines covered (74.64%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.2
/pwnlib/term/__init__.py
1
from __future__ import absolute_import
1✔
2
from __future__ import division
1✔
3

4
import sys
1✔
5

6
from pwnlib.term import completer
1✔
7
from pwnlib.term import key
1✔
8
from pwnlib.term import keymap
1✔
9
from pwnlib.term import readline
1✔
10
from pwnlib.term import term
1✔
11
from pwnlib.term import termcap
1✔
12
from pwnlib.term import text
1✔
13

14
# Re-exports (XXX: Are these needed?)
15
term.update_geometry()
1✔
16
width = term.width
1✔
17
height = term.height
1✔
18
output = term.output
1✔
19
getkey = key.get
1✔
20
Keymap = keymap.Keymap
1✔
21

22
#: This is True exactly when we have taken over the terminal using :func:`init`.
23
term_mode = False
1✔
24

25
def can_init():
1✔
26
    """This function returns True iff stderr is a TTY and we are not inside a
27
    REPL.  Iff this function returns `True`, a call to :meth:`init` will let
28
    ``pwnlib`` manage the terminal.
29
    """
30

31
    if sys.platform == 'win32':
1!
32
        return False
×
33

34
    if not sys.stdout.isatty():
1✔
35
        return False
1✔
36

37
    # Check for python -i
38
    if sys.flags.interactive:
1!
39
        return False
×
40

41
    # Check fancy REPLs
42
    mods = sys.modules.keys()
1✔
43
    for repl in ['IPython', 'bpython', 'dreampielib', 'jupyter_client._version']:
1✔
44
        if repl in mods:
1!
45
            return False
×
46

47
    # The standard python REPL will have co_filename == '<stdin>' for some
48
    # frame. We raise an exception to set sys.exc_info so we can unwind the call
49
    # stack.
50
    try:
1✔
51
        raise BaseException
1✔
52
    except BaseException:
1✔
53
        frame = sys.exc_info()[2].tb_frame
1✔
54

55
    while frame:
1✔
56
        if frame.f_code.co_filename == '<stdin>':
1!
57
            return False
×
58
        frame = frame.f_back
1✔
59

60
    return True
1✔
61

62

63
def init():
1✔
64
    """Calling this function will take over the terminal (iff :func:`can_init`
65
    returns True) until the current python interpreter is closed.
66

67
    It is on our TODO, to create a function to "give back" the terminal without
68
    closing the interpreter.
69
    """
70

71
    global term_mode
72

73
    if term_mode:
1!
74
        return
×
75

76
    if not can_init():
1✔
77
        return
1✔
78

79
    term.init()
1✔
80
    def update_geometry():
1✔
81
        global height, width
82
        height = term.height
1✔
83
        width = term.width
1✔
84
    update_geometry()
1✔
85
    term.on_winch.append(update_geometry)
1✔
86
    readline.init()
1✔
87

88
    term_mode = True
1✔
89
    text.num_colors = termcap.get('colors', default = 8) or 8
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc