aboutsummaryrefslogtreecommitdiffstats
path: root/testing/idris2/0001-Flush-standard-out-after-writing-prompt-to-it.patch
blob: 1c53789e821078377802d2dd89c487aa8173854b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
From bd1d67f89bbbf28d8d8d56214b05568195be27b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
Date: Sun, 28 Feb 2021 10:00:20 +0100
Subject: [PATCH] Flush standard out after writing prompt to it

On Unix-like operating systems stdio.h is usually line-buffered. As
putStr uses fputs(3) from stdio.h internally, output will be written to
standard out after a newline character is written to the buffer. Since
the prompt does not contain a newline, it will only be written to
standard output after the user presses return. I encountered this issue
on Alpine Linux which uses musl libc (instead of glibc). However, I
believe this issue is likely also reproducible with glibc. This commit
fixes this issue by flushing standard output after writing the prompt to
it. Surprisingly, `src/Idris/IDEMode/REPL.idr` already does this
correctly, `src/Idris/REPL.idr` does not though.
---
 src/Idris/REPL.idr | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/Idris/REPL.idr b/src/Idris/REPL.idr
index d1aede40..53f3eca6 100644
--- a/src/Idris/REPL.idr
+++ b/src/Idris/REPL.idr
@@ -897,6 +897,7 @@ mutual
       = do ns <- getNS
            opts <- get ROpts
            coreLift (putStr (prompt (evalMode opts) ++ show ns ++ "> "))
+           coreLift (fflush stdout)
            inp <- coreLift getLine
            end <- coreLift $ fEOF stdin
            if end