Hello all, As I continue to familiarize myself with chicken scheme, I try to migrate some of my desktop scripts from ruby to scheme. Those are not complex apps, but they are dealing with numerous call to other programs, either to do something, retrieve a value or both.
I’m writing today to check whether I correctly understood something, or not, and what I could do to work around a little glitch I encounter. This issue is visible with the following 2 scripts: - https://git.umaneti.net/shell_utils/tree/vscode_proxy.scm - https://git.umaneti.net/shell_utils/tree/open_firefox.scm Let’s focus on the second one. The main idea is to let me choose a Firefox profile before opening the browser (yes I know about firefox -P, this is not the subject ^^). To do so I’m willing to use fuzzel, which is an handy selectors, like rofi or dmenu. Main change from rofi is that fuzzel is wayland native (probably good time to say I’m working on a Linux box, with chicken 6, using sway (a light wayland window manager)). Fuzzel (as rofi/demu) works by passing it data on stdin, then reading the chosen item on stdout. So basically I define a variable, holding (process "fuzzel"…), then write on its (process-input-port), and finally wait for data on (process-output-port). And it works. Almost. Here is the interesting part of the code: (let* ((fuzzel-proc (process "fuzzel" `("--dmenu" "--log-level" "error" "--prompt" "🦊 " "--placeholder" ,(uri-or-search-label uri-or-search)))) (fuzzel-stdin (process-input-port fuzzel-proc)) (fuzzel-stdout (process-output-port fuzzel-proc))) (let send-to-fuzzel ((payload (fuzzel-payload))) (unless (null? payload) (write-line (car payload) fuzzel-stdin) (send-to-fuzzel (cdr payload)))) (close-input-port fuzzel-stdin) (let ((answer (read-line fuzzel-stdout))) (close-output-port fuzzel-stdout) (receive (process-wait fuzzel-proc)) answer)))) Here is the catch: previously, with my ruby implementation, using Open3.catpure2 method, fuzzel starts and displays icons next to the text entries. With the same data, the chicken implementation shows the text, but icons are missing. I first thought it comes from the way I format the data on stdin (how to write specific ascii chars like null byte), but after hacking into fuzzel to output some debug logs, it appears the issue is not with the data. What happen, from my debug log, is that fuzzel process the stdin data, then once I close the stdin port, I move to a loop to "read-line" on stdout. And doing so seems to freeze fuzzel. It is displayed on screen and I can choose an item, and it correctly write the chosen item on stdout ; but it’s like the main procedure is frozen between the item display in list and the icon display (not sure how to debug that). If I remove the stdout-reading part (so make my script useless, but it’s a test), icons correctly appears next to the text. With my first script (vscode_proxy), the issue is a bit similar: I try to update a zenity progress bar with value coming from another process stderr (could be stdout). The script succeeds, but visually the progress bar never updates before the end of the first process. So I’m not an expert, but I’ve the feeling I’m not reading correctly data from stdout/stderr the way I should. It looks like all reading function I found are "blocking" from the subprocess point of view. I know my (long) message involves a lot of thing not related to chicken directly, but at this point I think I’ve tested everything I could (even reading chicken source code, very interesting). So please, if someone has a sudden brilliant idea about this situation, I’d be very happy :) Have a great day all, -- Étienne Pflieger https://etienne.pflieger.bzh
