[REBOL] Re: Console port and network ports
From: nitsch-lists:netcologne at: 11-Aug-2002 13:49
Am Sonntag, 11. August 2002 09:19 schrieb maarten koopmans:
> Hi,
>
> Is there a way to add a network port and a console port in one wait/all
> block? So I can process network events and console events, and once I
> have a complete "line" from the console do something with it.
>
> (other than using system/ports/wait-list).
>
> And how do I capture the control characters in /Core (up tab down etc.)
>
> --Maarten
Hope this helps :)
REBOL [Title: "minimuddy" Author: "Volker"
;--config
print "---" ;or crash (suse 8.0)
server-name: tcp://localhost:3333 ; homemud
;stop: does[unview/all halt]
stop: :quit
;--connecting mud
mud: open/direct/no-wait server-name
mud/awake: func [port /local new] [
either new: copy port [emit new] [stop]
false
]
append system/ports/wait-list mud
;--connecting console
;by jeff?
set 'con open/binary/direct [
scheme: 'console
awake: func [port /local c r face buf] [
buf: system/view/caret: tail enter/text
prin c: to-char first port
either find "^M^J" c [
print "" do-face ke none clear head buf
] [
;-- basic editing
either c = #"^h" [
remove back buf
] [insert buf c buf: next buf]
]
system/view/caret: buf show enter
false
]
]
append system/ports/wait-list con
;--connecting window
log: cp""
window: layout [
origin 0x0
enter: field 350x48
ke: key keycode [#"^s" #"^m"] [
send-command enter/text
system/view/caret: clear enter/text
show enter
]
below
log-face: info log 350x100 wrap
]
;--emit, send-command
set 'emit func [string /local face] [
prin string
face: log-face
append face/text string
face/para/scroll/y: negate max 0
((second size-text face) - face/size/y + 10)
show log-face
]
set 'send-command func [string] [
insert mud join string newline
emit reduce ["home>" string newline]
]
focus enter
view window