Question: ( @problem 1 ) ;; A * SIMPLE * one line text editor ;; ;; The screen looks like: ;; ;; ab | c ;;

(@problem 1)
;; A *SIMPLE* one line text editor
;;
;; The screen looks like:
;;
;; ab|c
;;
;; where | is the cursor.
;;
;; Typing characters inserts them.
;; left and right arrow moves cursor
;; delete removes character before cursor
(@htdw Editor)
;; =================
;; Constants:
(define WIDTH 200)
(define HEIGHT 20)
(define TEXT-SIZE 18)
(define TEXT-COLOR "BLACK")
(define CURSOR (rectangle 120 "solid" "red"))
(define MTS (empty-scene WIDTH HEIGHT))
;; =================
;; Data Definitions:
(@htdd Editor)
(define-struct editor (pre post))
;; Editor is (make-editor String String)
;; interp. (make-editor pre post) is an editor
;; pre is text before cursor
;; post is text after cursor
(define ED1(make-editor """"))
(define ED2(make-editor "abc" "d"))
(define ED3(make-editor "abcd" ""))
(define ED4(make-editor "" "abcd"))
(@dd-template-rules compound) ;; 2 fields
(define (fn-for-editor e)
(...(editor-pre e)
(editor-post e)))
;; =================
;; Functions:
(@htdf run-editor)
(@signature String -> Editor)
;; run an editor, with pre as the initial text preceding the cursor
(@template-origin htdw-main)
(define (run-editor pre)
(big-bang (make-editor pre "")
(to-draw render) ; Editor -> Image
(on-key handle-key))) ; Editor KeyEvent -> Editor
(@htdf render)
(@signature Editor -> Image)
;; place text with cursor at left, middle edge of MTS
(check-expect (render (make-editor "a""bc"))
(overlay/align "left"
"middle"
(beside (text "a" TEXT-SIZE TEXT-COLOR)
CURSOR
(text "bc" TEXT-SIZE TEXT-COLOR))
MTS))
;(define (render e) MTS) ;stub
(@template-origin Editor)
(@template
(define (render e)
(...(editor-pre e)
(editor-post e))))
Complete render
The starter contains an incomplete function design for render with an example and function template. Please comment out the stub and complete the function definition.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!