Add ainput function

This commit is contained in:
Dan 2018-07-02 14:10:26 +02:00
parent 3711437dbd
commit 26bb97af46

View file

@ -16,9 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import asyncio
import logging import logging
import sys
import time import time
from base64 import b64decode, b64encode from base64 import b64decode, b64encode
from concurrent.futures.thread import ThreadPoolExecutor
from struct import pack from struct import pack
from weakref import proxy from weakref import proxy
@ -57,6 +60,13 @@ class Str(str):
return self._client.html.unparse(self, self._entities) return self._client.html.unparse(self, self._entities)
async def ainput(prompt: str = ""):
with ThreadPoolExecutor(1, "AsyncInput", lambda x: print(x, end="", flush=True), (prompt,)) as executor:
return (await asyncio.get_event_loop().run_in_executor(
executor, sys.stdin.readline
)).rstrip()
ENTITIES = { ENTITIES = {
types.MessageEntityMention.ID: "mention", types.MessageEntityMention.ID: "mention",
types.MessageEntityHashtag.ID: "hashtag", types.MessageEntityHashtag.ID: "hashtag",