Skip to content

Commit abd1302

Browse files
committed
clear: Add clear.py
1 parent 00526df commit abd1302

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/clear.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/python3
2+
3+
import sys
4+
from optparse import OptionParser
5+
6+
# clear(1), roughly modelled off the ncurses implementation.
7+
8+
9+
def clear(opts):
10+
print("\x1b[2J\x1b[H", end="")
11+
if not opts.x:
12+
print("\x1b[3J", end="")
13+
14+
15+
if __name__ == "__main__":
16+
parser = OptionParser(
17+
usage="Usage: %prog [OPTION]...",
18+
description="Clear the terminal screen.",
19+
add_help_option=False,
20+
)
21+
parser.add_option("--help", action="help", help="show usage information and exit")
22+
23+
parser.add_option("-T", metavar="TERM", help="(unimplemented)")
24+
25+
parser.add_option(
26+
"-x", action="store_true", help="do not try to clear the scrollback buffer"
27+
)
28+
29+
opts, args = parser.parse_args()
30+
31+
if args:
32+
sys.exit(1)
33+
34+
clear(opts)

0 commit comments

Comments
 (0)