From 8afd43527b29fc25b668576247cbf60d8f67ef5e Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sun, 27 Mar 2022 16:50:19 +0900 Subject: [PATCH] Use os.get_terminal_size; random got some fixes upstream --- ponysay/__init__.krk | 2 ++ ponysay/common.krk | 10 ++-------- ponysay/ponysay.krk | 6 +----- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/ponysay/__init__.krk b/ponysay/__init__.krk index 95bc3a61..43efe288 100644 --- a/ponysay/__init__.krk +++ b/ponysay/__init__.krk @@ -44,12 +44,14 @@ from ponysay.argparser import ArgParser from ponysay.ponysay import Ponysay import os import kuroko +import random ''' Start the program ''' if __name__ == '__main__': + random.seed() let istool = kuroko.argv[0] if os.sep in istool: istool = istool[istool.rfind(os.sep) + 1:] diff --git a/ponysay/common.krk b/ponysay/common.krk index 1bbae95e..6e763106 100644 --- a/ponysay/common.krk +++ b/ponysay/common.krk @@ -70,12 +70,6 @@ def gettermsize(): @return (rows, columns):(int, int) The number or lines and the number of columns in the terminal's display area ''' - # TODO we don't have a thing for this?? - try: - os.system("stty size > /tmp/.ponysaysize") - with fileio.open("/tmp/.ponysaysize") as f: - let tmp = f.read().strip() - return tuple(int(x) for x in tmp.split(' ')) - except: - return (24, 80) # fall back to minimal sane size + let columns, rows = os.get_terminal_size() + return rows, columns diff --git a/ponysay/ponysay.krk b/ponysay/ponysay.krk index e4a85415..a0b0f6bc 100755 --- a/ponysay/ponysay.krk +++ b/ponysay/ponysay.krk @@ -45,11 +45,7 @@ import stat import random def randrange(low,high): - with fileio.open('/dev/urandom','rb') as f: - let b = f.read(4) - let val = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3] - let flt = val / 0xFFFFFFFF - return int(flt*(high-low)+low) + return int(random.random() * (high - low) + low) def rfind(self, sub): let last = self.find(sub)