From 74f93f809a2d53d3412f3cf7ad100fc2c1590e01 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 18 Apr 2024 12:45:22 +0200 Subject: [PATCH] feat: user input with nano --- python/user_input_nano.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 python/user_input_nano.py diff --git a/python/user_input_nano.py b/python/user_input_nano.py new file mode 100644 index 0000000..8ec9bb6 --- /dev/null +++ b/python/user_input_nano.py @@ -0,0 +1,15 @@ +from pathlib import Path +import tempfile +import subprocess + +def input_nano() -> str: + f = tempfile.NamedTemporaryFile(mode='w+t', delete=False) + n = f.name + f.close() + subprocess.call(['nano', n]) + + with open(n, 'r') as f: + input_string = f.read() + Path(n).unlink() + + return input_string