From 183fad9de3cd73a1a8d5b0a4706ca2654ae30358 Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Sun, 23 Apr 2017 11:15:58 -0400 Subject: Now prompts for user name via the GUI --- Hermes/GUI.rkt | 11 ++++++++++- Hermes/client.rkt | 7 +++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Hermes/GUI.rkt b/Hermes/GUI.rkt index 30d305b..d3ff29a 100644 --- a/Hermes/GUI.rkt +++ b/Hermes/GUI.rkt @@ -84,6 +84,7 @@ (send input set-value "") ) + ; retrieves a message user inputed to the text field (define (get-message) (define one-message (if (not (null? messages)) @@ -191,13 +192,20 @@ ; specified (define height 15) ; height between messages drawn on the screen + ;; prompt user for username + ;; could randomly assign a user + (define (get-username) + (get-text-from-user "Username set-up" "Please enter a username" + main-frame "user" (list 'disallow-invalid) + #:validate string? )) + ;;dispatch goes below that ;; TODO get username function maybe (define (dispatch command) ; show gui should return the users the name as well as its first message ; to be called (cond ((eq? command 'show) (lambda () (send main-frame show #t))) - ((eq? command 'gui-input-port)) + ((eq? command 'get-username) get-username) ((eq? command 'send) send-message) ;; call to show a message in a gui ((eq? command 'set-name) (lambda (newname) (if (string? newname) (set! name newname) @@ -220,6 +228,7 @@ + ;Initilize scrolling ;Then we need to find out if we need them or not. diff --git a/Hermes/client.rkt b/Hermes/client.rkt index b2ca903..d94fc70 100644 --- a/Hermes/client.rkt +++ b/Hermes/client.rkt @@ -48,8 +48,9 @@ ; create a gui object ; (define hermes-gui (make-gui)) ; ((hermes-gui 'show)) - (displayln "What's your name?") - (define username (read-line)) + ;(displayln "What's your name?") + ;(define username (read-line)) + (define username ((hermes-gui 'get-username))) ;send the username to the server (username in out) (displayln username out) @@ -95,6 +96,8 @@ ;; TODO read from GUI instead ;(define input (read-line)) (define input ((hermes-gui 'get-message))) + ; TODO prompt for color as well + ; TODO /quit instead of quit (cond ((string=? input "quit") (displayln (string-append date-print username " signing out. See ya!") out) -- cgit v1.2.3