mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-06 07:15:30 -04:00
Merge branch 'generate-alt-random-writes-fixes'
This commit is contained in:
commit
070f102605
2 changed files with 48 additions and 13 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -29,9 +29,19 @@
|
||||||
## Unreleased
|
## Unreleased
|
||||||
### Added
|
### Added
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
* `generate-alt-random-writes.py --sixel`: width and height of emitted
|
||||||
|
sixels has been adjusted.
|
||||||
|
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
### Removed
|
### Removed
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
* `generate-alt-random-writes.py --sixel` sometimes crashing,
|
||||||
|
resulting in PGO build failures.
|
||||||
|
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
### Contributors
|
### Contributors
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@
|
||||||
import argparse
|
import argparse
|
||||||
import enum
|
import enum
|
||||||
import fcntl
|
import fcntl
|
||||||
import struct
|
|
||||||
import random
|
import random
|
||||||
|
import signal
|
||||||
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import termios
|
import termios
|
||||||
|
|
||||||
|
|
@ -37,17 +38,36 @@ def main():
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
out = opts.out if opts.out is not None else sys.stdout
|
out = opts.out if opts.out is not None else sys.stdout
|
||||||
|
|
||||||
try:
|
if opts.rows is None or opts.cols is None:
|
||||||
lines, cols, height, width = struct.unpack(
|
try:
|
||||||
'HHHH',
|
def dummy(*args):
|
||||||
fcntl.ioctl(sys.stdout.fileno(),
|
"""Need a handler installed for sigwait() to trigger."""
|
||||||
termios.TIOCGWINSZ,
|
pass
|
||||||
struct.pack('HHHH', 0, 0, 0, 0)))
|
signal.signal(signal.SIGWINCH, dummy)
|
||||||
except OSError:
|
|
||||||
lines = None
|
while True:
|
||||||
cols = None
|
with open('/dev/tty', 'rb') as pty:
|
||||||
height = None
|
lines, cols, height, width = struct.unpack(
|
||||||
width = None
|
'HHHH',
|
||||||
|
fcntl.ioctl(pty,
|
||||||
|
termios.TIOCGWINSZ,
|
||||||
|
struct.pack('HHHH', 0, 0, 0, 0)))
|
||||||
|
|
||||||
|
if width > 0 and height > 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
# We’re early; the foot window hasn’t been mapped yet. Or,
|
||||||
|
# to be more precise, fonts haven’t yet been loaded,
|
||||||
|
# meaning it doesn’t have any cell geometry yet.
|
||||||
|
signal.sigwait([signal.SIGWINCH])
|
||||||
|
|
||||||
|
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
|
||||||
|
|
||||||
|
except OSError:
|
||||||
|
lines = None
|
||||||
|
cols = None
|
||||||
|
height = None
|
||||||
|
width = None
|
||||||
|
|
||||||
if opts.rows is not None:
|
if opts.rows is not None:
|
||||||
lines = opts.rows
|
lines = opts.rows
|
||||||
|
|
@ -59,6 +79,11 @@ def main():
|
||||||
if lines is None or cols is None or height is None or width is None:
|
if lines is None or cols is None or height is None or width is None:
|
||||||
raise Exception('could not get terminal width/height; use --rows and --cols')
|
raise Exception('could not get terminal width/height; use --rows and --cols')
|
||||||
|
|
||||||
|
assert lines > 0, f'{lines}'
|
||||||
|
assert cols > 0, f'{cols}'
|
||||||
|
assert width > 0, f'{width}'
|
||||||
|
assert height > 0, f'{height}'
|
||||||
|
|
||||||
# Number of characters to write to screen
|
# Number of characters to write to screen
|
||||||
count = 256 * 1024**1
|
count = 256 * 1024**1
|
||||||
|
|
||||||
|
|
@ -176,7 +201,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
# Random origin in upper left quadrant
|
# Random origin in upper left quadrant
|
||||||
last_pos = random.randrange(lines // 2) + 1, random.randrange(cols // 2) + 1
|
last_pos = random.randrange(lines // 2) + 1, random.randrange(cols // 2) + 1
|
||||||
last_size = random.randrange(height // 2), random.randrange(width // 2)
|
last_size = random.randrange((height + 1) // 2), random.randrange((width + 1) // 2)
|
||||||
|
|
||||||
out.write(f'\033[{last_pos[0]};{last_pos[1]}H')
|
out.write(f'\033[{last_pos[0]};{last_pos[1]}H')
|
||||||
six_height, six_width = last_size
|
six_height, six_width = last_size
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue