Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gsauthof-utility
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
external
gsauthof-utility
Commits
47c09331
Commit
47c09331
authored
3 years ago
by
Georg Sauthoff
Browse files
Options
Downloads
Patches
Plain Diff
add detect-size - detect and set real geometry of a terminal
parent
8992696f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+1
-0
1 addition, 0 deletions
CMakeLists.txt
README.md
+2
-0
2 additions, 0 deletions
README.md
detect-size.py
+49
-0
49 additions, 0 deletions
detect-size.py
with
52 additions
and
0 deletions
CMakeLists.txt
+
1
−
0
View file @
47c09331
...
@@ -163,6 +163,7 @@ set(scripts
...
@@ -163,6 +163,7 @@ set(scripts
check-dnsbl.py
check-dnsbl.py
chromium-extensions.py
chromium-extensions.py
cpufreq.py
cpufreq.py
detect-size.py
devof.sh
devof.sh
disas.sh
disas.sh
firefox-addons.py
firefox-addons.py
...
...
This diff is collapsed.
Click to expand it.
README.md
+
2
−
0
View file @
47c09331
...
@@ -31,6 +31,8 @@ This repository contains a collection of command line utilities.
...
@@ -31,6 +31,8 @@ This repository contains a collection of command line utilities.
-- decompressing cat (autodetects gzip/zstd/bz2/...)
-- decompressing cat (autodetects gzip/zstd/bz2/...)
-
[
dcheck
](
#dcheck
)
-
[
dcheck
](
#dcheck
)
-- run a program under DBX's memory check mode
-- run a program under DBX's memory check mode
-
detect-size
-- detect and set real height/width of a terminal
-
devof
-
devof
-- list network device names given an address (prefix)
-- list network device names given an address (prefix)
-
disas
-
disas
...
...
This diff is collapsed.
Click to expand it.
detect-size.py
0 → 100755
+
49
−
0
View file @
47c09331
#!/usr/bin/env python3
# detect-size - detect and set real height/width of a terminal
#
# replacement for xterm's resize command for systems that
# don't package it separately (e.g. in xterm-resize as Fedora does)
#
# useful for terminals that are attached to a serial line,
# including emulated ones (e.g. on a VM)
#
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: © 2021 Georg Sauthoff <mail@gms.tf>
import
fcntl
import
os
import
struct
import
sys
import
termios
import
tty
def
main
():
# source: https://sources.debian.org/src/xterm/366-1/resize.c/?hl=137#L139
print
(
'
\x1b
'
'
7
'
'
\x1b
'
'
[r
'
'
\x1b
'
'
[9999;9999H
'
'
\x1b
'
'
[6n
'
,
flush
=
True
,
end
=
''
)
# cf. https://stackoverflow.com/q/40931467/427158
bak
=
termios
.
tcgetattr
(
sys
.
stdin
.
fileno
())
tty
.
setcbreak
(
sys
.
stdin
.
fileno
())
r
=
b
''
.
join
(
iter
(
lambda
:
os
.
read
(
sys
.
stdin
.
fileno
(),
1
),
b
'
R
'
))
termios
.
tcsetattr
(
sys
.
stdin
.
fileno
(),
termios
.
TCSADRAIN
,
bak
)
i
=
r
.
rindex
(
b
'
[
'
)
j
=
r
.
index
(
b
'
;
'
)
h
=
int
(
r
[
i
+
1
:
j
])
w
=
int
(
r
[
j
+
1
:])
x
=
struct
.
pack
(
'
HHHH
'
,
h
,
w
,
0
,
0
)
print
(
f
'
\r
height:
{
h
}
, width:
{
w
}
'
)
fcntl
.
ioctl
(
sys
.
stdout
,
termios
.
TIOCSWINSZ
,
x
)
# alternatively: ioctl() on /dev/tty
if
__name__
==
'
__main__
'
:
sys
.
exit
(
main
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment