Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3437316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:03:00+00:00 2026-05-18T08:03:00+00:00

Would like to detect esc key to escape the forever loop in pseudo code:

  • 0

Would like to detect esc key to escape the forever loop in pseudo code:

forever [
url: ask “Url: ”
if (url = esc) [
break
]
]

Is this possible ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:03:01+00:00Added an answer on May 18, 2026 at 8:03 am

    There is no simple answer, you must use own console-port to handle it correctly, here is the part of it taken from one of my old projects:

    REBOL [title: "Console port"]
    
    set 'ctx-console make object! [
        system/console/busy: none
        system/console/break: false
        buffer: make string! 512
        history: system/console/history
        prompt: "## " ;system/console/prompt
        spec-char: none
        port: none
        init: func[][
            port: open/binary [scheme: 'console]
            set 's-print get in system/words 'print
            set 's-prin  get in system/words 'prin
            set 'prin func[msg /err /inf /user user-data][
                ctx-console/clear-line
                s-prin reform msg
                ctx-console/print-line
            ]
            set 'print func[msg /err /inf /user user-data][
                prin rejoin [reform msg newline]
            ]
            s-prin prompt
        ]
        print-line: func[][
            s-prin rejoin [ prompt head buffer "^(1B)[" length? buffer "D"]
        ]
        clear-line: func[][
            s-prin rejoin [
                "^(1B)[" (
                (index? buffer) +
                (length? prompt) +
                (length? buffer))
                "D^(1B)[K"
            ]
        ]
        key-actions: make block! [
            #{08} [;BACK
                if 0 < length? head buffer [
                    buffer: remove back buffer
                    s-prin rejoin [
                        "^(back)^(1B)[K"
                        buffer
                        "^(1B)["
                        length? buffer "D"
                    ]
                ]
            ]
            #{7E} [;HOME
                s-prin rejoin ["^(1B)[" (index? buffer) - 1 "D"]
                buffer: head buffer
            ]
            #{7F} [;DELETE
                buffer: remove buffer
                s-prin rejoin ["^(1B)[K" buffer "^(1B)[" length? buffer "D"]
            ]
            #{1B} [;ESCAPE
                spec-char: copy/part port 1
                either spec-char = #{1B} [
                    print "ESCAPE"
                    clear-line
                    set 'print :s-print
                    set 'prin  :s-prin
                    system/console/break: true
                    on-escape
                ][
                    switch append spec-char copy/part port 1 [
                        #{5B41} [;ARROW UP
                            if not tail? history [
                                clear-line
                                clear head buffer
                                s-prin join prompt buffer: copy history/1
                                history: next history
                                buffer: tail buffer
                            ]
                        ]
                        #{5B42} [;ARROW DOWN
                            clear-line
                            buffer: head buffer
                            clear buffer
                            if all [
                                not error? try [history: back history]
                                not none? history/1
                            ] [
                                buffer: copy history/1
                            ]
                            s-prin join prompt buffer
                            buffer: tail buffer
                        ]
                        #{5B43} [;ARROW RIGHT
                            if not tail? buffer [
                                s-prin "^(1B)[C"
                                buffer: next buffer
                            ]
                        ]
                        #{5B44} [;ARROW LEFT
                            if 1 < index? buffer [
                                s-prin "^(1B)[D"
                                buffer: back buffer
                            ]
                        ]
                    ]
                ]
            ]
        ]
        do-command: func[comm /local e][
            set/any 'e attempt compose [do (comm)]
    
            if all [
                not unset? 'e
                value? 'e
                not object? :e
                not port? :e
                not function? :e
            ][
                print head clear skip rejoin [system/console/result mold :e] 127
                if (length? mold :e) > 127 [
                    print "...^/"
                ]
            ]
        ]
        on-enter: func[input-str /local e][
            print rejoin [system/console/prompt input-str]
            do-command input-str
        ]
        on-escape: func[][halt]
        process: func[/local ch c tmp spec-char err][
            ch: to-char pick port 1
            either (ch = newline) or (ch = #"^M") [;ENTER
                tmp: copy head buffer
                if empty? tmp [return none]
                history: head history
                if any [empty? history tmp <> first history ] [
                    insert history tmp
                ]
                clear-line
                buffer: head buffer
                clear buffer
                print-line
                on-enter tmp
            ][
                switch/default to-binary ch key-actions [
                    either tail? buffer [
                        s-prin ch ;either local-echo [ch]["*"]
                    ][
                        s-prin rejoin ["^(1B)[@" ch]
                    ]
                    buffer: insert buffer ch
                ]
            ]
        ]
    ]
    ctx-console/init
    
    ;and now do something with your own console:
    wait-list: reduce [ctx-console/port]
    forever [
        attempt [ready: wait/all wait-list]
        if ready [
            ctx-console/process
        ]
    ]
    

    You will probably like to change the ctx-console/on-escape and ctx-console/on-enter functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.