From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Read characters from without newline Date: Sat, 28 Aug 2021 14:09:52 +0000 Message-ID: <3ea2d7b2-019e-a226-9166-34edaec52fd4@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14740"; mail-complaints-to="usenet@ciao.gmane.io" To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Aug 28 16:10:12 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 1mJz2C-0003cc-8x for guile-user@m.gmane-mx.org; Sat, 28 Aug 2021 16:10:12 +0200 Original-Received: from localhost ([::1]:55762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJz2A-0007T3-Ri for guile-user@m.gmane-mx.org; Sat, 28 Aug 2021 10:10:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJz1z-0007Sk-Ty for guile-user@gnu.org; Sat, 28 Aug 2021 10:09:59 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:38449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJz1x-0000iC-Cm for guile-user@gnu.org; Sat, 28 Aug 2021 10:09:59 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 4B39F240026 for ; Sat, 28 Aug 2021 16:09:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1630159794; bh=PzXcIVWlq+ZIbw5pt0gew6mYXG/O3CcOSrAZ7iRAiDw=; h=To:From:Subject:Date:From; b=Whd1uq5pDURy+sjoT4LHuVaho3xFZJzUz4OV6zeWtjhiV51AmVBTTKWHcQ/x80Na3 xfKc0LKrO+QFGwFCQhqqcmAjfpbtgQj01ShULFNLZjIKfcE9ooAV74aOTghYQ5NS7T MgNfNcoGvXa+zgAzTrfu/vtsZWaoAbli+sCrdawiNoT4biuSQ0x23MYXaNHGWmXUUe y9tqBfMs/12/x3mKc4ZOBoLJwlamSZ8Q7o3KCpVBdPxrf6ypCGnMUQe63+pykDeOrQ 2UrzwUHxGWbRdMGGxwQVG7+dh6X8xbUrFfu6JeYDN27omZDghA6MFn+8t6PWDmgmfe 9M+RVUPEyUayQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Gxdkn5Bz5z9rxK for ; Sat, 28 Aug 2021 16:09:53 +0200 (CEST) Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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:17696 Archived-At: 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. However, I am not sure how the Python solution does this. I have some command line program, in which I let the user choose what to do next by entering a character and then pressing the return key to confirm the input. I think it would be nice to not have to press return all the time and only needing to press the character's key. Does anyone know how to do this in Guile? Best regards, Zelphir -- repositories: https://notabug.org/ZelphirKaltstahl