From 7db98cdedf70dd2b4a9b3a608d69eb59a581f957 Mon Sep 17 00:00:00 2001 From: Oldes Huhuman Date: Wed, 29 Jan 2025 18:30:49 +0100 Subject: [PATCH] FIX: Skip bracketed paste mode initialization on POSIX when using `--cgi` flag --- src/include/reb-device.h | 5 +++-- src/mezz/mezz-help.reb | 3 +-- src/os/host-main.c | 4 ++-- src/os/host-stdio.c | 6 ++++-- src/os/posix/dev-stdio.c | 13 +++++++++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/include/reb-device.h b/src/include/reb-device.h index d4f8bdfbbe..16623138d1 100644 --- a/src/include/reb-device.h +++ b/src/include/reb-device.h @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2013-2024 Rebol Open Source Developers +** Copyright 2013-2025 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -118,7 +118,8 @@ enum { enum { RDM_NULL, // Null device - RDM_READ_LINE, + RDM_READ_LINE, // Read line mode + RDM_CGI }; // Serial Parity diff --git a/src/mezz/mezz-help.reb b/src/mezz/mezz-help.reb index fb7aa50fc0..3b3c2e625e 100644 --- a/src/mezz/mezz-help.reb +++ b/src/mezz/mezz-help.reb @@ -497,6 +497,7 @@ import (module [ ^[[1;32m--secure policy^[[m Can be: none allow ask throw quit ^[[1;32m--trace (-t)^[[m Enable trace mode during boot ^[[1;32m--verbose^[[m Show detailed startup information + ^[[1;32m--cgi (-c)^[[m Starts in a CGI mode ^[[4;1;36mOther quick options^[[m: @@ -510,8 +511,6 @@ import (module [ REBOL -s script.r REBOL script.r 10:30 test@example.com REBOL --do "watch: on" script.r} - - ; --cgi (-c) Load CGI utiliy module and modes ] diff --git a/src/os/host-main.c b/src/os/host-main.c index bf01087f17..416ce691ab 100644 --- a/src/os/host-main.c +++ b/src/os/host-main.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2021-2023 Rebol Open Source Developers +** Copyright 2021-2025 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -349,7 +349,7 @@ int main(int argc, char **argv) { Parse_Args(argc, (REBCHR **)argv, &Main_Args); - cgi = Main_Args.options & RO_CGI; + cgi = RO_CGI == (Main_Args.options & RO_CGI); // Must be done before an console I/O can occur. Does not use reb-lib, // so this device should open even if there are other problems. diff --git a/src/os/host-stdio.c b/src/os/host-stdio.c index 2e591a88e5..5eef76a945 100644 --- a/src/os/host-stdio.c +++ b/src/os/host-stdio.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2021-2023 Rebol Open Source Developers +** Copyright 2021-2025 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -128,7 +128,9 @@ static int Fetch_Buf() inbuf = OS_Make(inbuf_len); inbuf[0] = 0; - if (!cgi) + if (cgi) + SET_FLAG(Std_IO_Req.modes, RDM_CGI); + else SET_FLAG(Std_IO_Req.modes, RDM_READ_LINE); return &Std_IO_Req; } diff --git a/src/os/posix/dev-stdio.c b/src/os/posix/dev-stdio.c index c5f8e83685..0cdcb24079 100644 --- a/src/os/posix/dev-stdio.c +++ b/src/os/posix/dev-stdio.c @@ -3,6 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies +** Copyright 2012-2025 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -579,8 +580,10 @@ static void Close_StdIO_Local(void) tcsetattr(Std_Inp, TCSANOW, &original_settings); - // Turn off bracketed paste - https://cirw.in/blog/bracketed-paste - printf("\e[?2004l"); + if(!GET_FLAG(req->modes, RDM_CGI)) { + // Turn off bracketed paste - https://cirw.in/blog/bracketed-paste + printf("\e[?2004l"); + } } else { //printf("char inp %s\n", dev->title); @@ -593,8 +596,10 @@ static void Close_StdIO_Local(void) //flags |= O_NONBLOCK; tcsetattr(Std_Inp, TCSANOW, &settings); - // Turn on bracketed paste - https://cirw.in/blog/bracketed-paste - printf("\e[?2004h"); + if(!GET_FLAG(req->modes, RDM_CGI)) { + // Turn on bracketed paste - https://cirw.in/blog/bracketed-paste + printf("\e[?2004h"); + } } //fcntl(Std_Inp, F_SETFL, flags);