From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mike Gran Newsgroups: gmane.lisp.guile.user Subject: Re: Read characters from without newline Date: Sat, 28 Aug 2021 07:52:21 -0700 Message-ID: References: <3ea2d7b2-019e-a226-9166-34edaec52fd4@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8669"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Aug 28 16:52:45 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJzhN-0001xf-3G for guile-user@m.gmane-mx.org; Sat, 28 Aug 2021 16:52:45 +0200 Original-Received: from localhost ([::1]:51374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJzhL-0000Ak-LA for guile-user@m.gmane-mx.org; Sat, 28 Aug 2021 10:52:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJzhB-0000Ac-7Y for guile-user@gnu.org; Sat, 28 Aug 2021 10:52:33 -0400 Original-Received: from sonic305-2.consmr.mail.bf2.yahoo.com ([74.6.133.41]:42697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mJzh9-0006NA-3f for guile-user@gnu.org; Sat, 28 Aug 2021 10:52:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1630162348; bh=ytRxD953KC7o3k76vP1rgIW9DMP4jno/Ms7nUrY2uZU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject:Reply-To; b=Hhw3vq8MD9//u10wPNvo7xY/kWmiElcSn2Ro0hETF068zoOmZp5nAJ6eN7mQh3REDkZI6rgCkKsQOH8FNHrdFpyl3XtVSlh07WmN/xT2AUY3I/KHwXbUwAcigjUKPEWy66U+AcdMmRu2RdQJFMq18iVoVVXoN96MrGAYRzTIE7QejU98ePtJdZeq5na8mIeSryymabYcCA9z3qCiy11ZoTgcy4VsP/CL/E6gu2Tp7+TTSMzqmxQ/V0gVf8CVotTU8vmSgyKLT/JERbdu9CBEn832DTpe6H5nXnbqH5FCjvMtIfsWkTq2tHiep8fh/sk89m7L1d1o7hFweaWger7Tfg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1630162348; bh=hxWoorgXCM8513nk0V05DawDCl+ejIc6D7/ZrjSSs3B=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=d4MGCkbneVQm/TKpx28+b+n9/5CQqbSRgcvhxKh+BaO7Ulaid/VFJE17YYYcjF8DpNmNzKrjoPPg5X2cDnBunMkHpuMjX6/KvXGQkk0bUMI/oJ4FpnK9Hx9prmqUEOfw58+obEMrmbHYWcwjjBsJ3V1SJGYKyxQhv/sfB7uxQ2b5YJ/C76zHx0wtboSYoWJu3WyGWCeYm79PCqgJ8lXulAJ4/c96MFUgpYQP/eDxC69iT/GEnuPcMpUFoRNAGhmv7wTbQU9yOdzjRRskZLTMzRKrmKgaENN7TzkFTY+mHyVXa2l6HKw0VSrGYasCjcgjMvVRrcjtXsmiFoxT+YQN0g== X-YMail-OSG: bKBz1qAVM1lsW78Srl28RdK3K0_11JkyTf9eLcvwcHO7DwiDLOj_6K20HK2G4D4 tyjyFKo0rbOLi9GYOjy.yQt9Yn7AR_1.e48S4.bZ4rD30FsoImWBhSj9dBmRB3qHdHKoSKFmy8L1 w3TtxRXVUe0pGu7Dvu.XP.8ly2gSffj9GG9yMD6fs8rKPxAC9iDtxjvCxaKisNhpgziikaEdIcd2 _NGrYMrSC6H89Jzt.dPE6zuuCt7lP4Cl5ZqasHvGQ4ZxBtvQtYe7D8RMgVvKrpdm7US3l6GlE0kh bpikHTQwfJNuncWg7BcGba_L4Z2E_Yhz1BknA3ch8TPVbbuidmbfWpfSUGCVGGfOJxp0aK2LcGXQ pLOYob0CRabygQEoxHGAU5Ft.Eh6GM67ji3fYCF1u8DF7ecl66cYm236.4S4XkcBfkhZQxMh8ljO lb4fPn6CGyxOuJwrKnJWxLy6H5xk0N52LTVnzURlwzKTJA3rMZXAjWW2aEnixQq4cgzxlnyYfxZC OKtUGshP5o_Bq8e6jXKWAOAy0c6Ku8PM3nB54U2jdC0eRrEIzukIwCGj2l13l7B.aFmnEMm2xXzR ABSL.QPq1NdYW4XP6fhYmFG24am4w7EbhNP__SL7SsI.Lvz3p3wc2D01kB3H0MZ2T9TIcaqKMbgA 1sebenL1ZDKdoUCNnjWlBubVCMjOt046mcxcbPozzl6oX9AlXQjwe30WzHX6XQBtZEYEoK_M_3ss apNuBRjS91fhN.upf9ylHUCW7RHonIUCvtxWgXKem36ujxI4MYpMlWDyl_gn3lrynmGMkDFrVvWV kF1aIlMbTt2FxiJGcYQQ0nsWTDtakhyiX01CA6xIOS X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.bf2.yahoo.com with HTTP; Sat, 28 Aug 2021 14:52:28 +0000 Original-Received: by kubenode528.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 598f54b6862d4471f1c247aae930dfc1; Sat, 28 Aug 2021 14:52:24 +0000 (UTC) Content-Disposition: inline In-Reply-To: <3ea2d7b2-019e-a226-9166-34edaec52fd4@posteo.de> X-Mailer: WebService/1.1.18924 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=74.6.133.41; envelope-from=spk121@yahoo.com; helo=sonic305-2.consmr.mail.bf2.yahoo.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17697 Archived-At: On Sat, Aug 28, 2021 at 02:09:52PM +0000, Zelphir Kaltstahl wrote: > Hello Guile users, > > I am trying to find a way to read a character from command line or REPL, without > having to enter a newline, confirming the input. > > For example I found this for Python: https://stackoverflow.com/a/21659588 > > > I read on https://www.gnu.org/software/guile/manual/html_node/Buffering.html > about > buffering and thought, that I could simply set the port to be unbuffered using > (setvbuf port 'none) and then call (get-char port) as follows: > > ~~~~ > (import > (except (rnrs base) let-values map) > (only (guile) > ;; lambda forms > lambda* ?? > ;; input output > current-input-port) > (ice-9 textual-ports) > (ice-9 optargs)) > > (let ([port (current-input-port)]) > (setvbuf port 'none) > (get-char port)) > ~~~~ > > However, this does not work. The terminal emulator might not send input > immediately to the Guile program. Even in the Guile REPL and in Emacs Geiser > this does not work. I guess it would work, if they did send each character > immediately to the Guile program, because the following works: > > ~~~~ > (display > (call-with-input-string "ab" > (?? (in-port) > (setvbuf in-port 'none) > (get-char in-port)))) > ~~~~ > > There is no newline in the string "ab" and only the "a" is displayed. > > So the question might be, how one can get into a mode, where Guile receives > input immediately, taking over control of the terminal or REPL. Hello. For this to work, your terminal needs to be in 'raw' mode where it sends characters immediately. Terminals are normally in 'cooked' mode where it waits for a return before it sends everything. The simple way to get into raw mode would be to run your script like stty raw && guile script.scm But if you want to get the terminal into raw mode from within guile, you need to get guile to call a function like 'tcsetattr' to set the mode of your terminal. Or maybe just call the stty program from within guile? There is a binding of tcsetattr in the (ncurses extra) library in guile-ncurses, but since you just need a couple of functions, you could wrap them in FFI, I suppose. -Mike