added live search facility for words to eval-responder

cvs
Chris Double 2004-08-01 22:26:07 +00:00
parent a91cda2e8f
commit 722a8f888c
1 changed files with 50 additions and 0 deletions

View File

@ -38,6 +38,9 @@ USE: errors
USE: strings USE: strings
USE: logic USE: logic
USE: combinators USE: combinators
USE: live-updater
USE: prettyprint
USE: vocabularies
: <evaluator> ( stack msg history -- ) : <evaluator> ( stack msg history -- )
#! Create an 'evaluator' object that holds #! Create an 'evaluator' object that holds
@ -102,6 +105,47 @@ USE: combinators
[ <tr> [ <td> [ write-eval-link ] </td> ] </tr> ] each [ <tr> [ <td> [ write-eval-link ] </td> ] </tr> ] each
] </table> ; ] </table> ;
: with-simple-html-output ( quot -- )
#! Run the quotation inside an HTML stream wrapped
#! around stdio.
<pre> [
"stdio" get <html-stream> [
call
] with-stream
] </pre> ;
: html-for-word-source ( word-string -- )
#! Return an html fragment dispaying the source
#! of the given word.
dup dup
<namespace> [
"responder" "inspect" put
<table border= "1" table> [
<tr> [ <th colspan= "2" th> [ "Source" write ] </th> ] </tr>
<tr> [ <td colspan= "2" td> [ [ see ] with-simple-html-output ] </td> ] </tr>
<tr> [ <th> [ "Apropos" write ] </th> <th> [ "Usages" write ] </th> ] </tr>
<tr> [ <td valign= "top" td> [ [ apropos. ] with-simple-html-output ] </td>
<td valign= "top" td> [ [ usages. ] with-simple-html-output ] </td>
] </tr>
] </table>
] bind ;
: display-word-see-form ( url -- )
#! Write out the html for code that accepts
#! the name of a word, and displays the source
#! code of that word.
<form method= "post" action= "." form> [
[
[
"Enter the name of a word: " write
"see" [ html-for-word-source ] live-search
]
[
<div id= "see" div> [ "" write ] </div>
]
] vertical-layout
] </form> ;
: display-last-output ( string -- ) : display-last-output ( string -- )
#! Write out html to display the last output. #! Write out html to display the last output.
<table border= "1" table> [ <table border= "1" table> [
@ -109,12 +153,17 @@ USE: combinators
<tr> [ <td> [ <pre> [ write ] </pre> ] </td> ] </tr> <tr> [ <td> [ <pre> [ write ] </pre> ] </td> ] </tr>
] </table> ; ] </table> ;
: get-expr-to-eval ( -- string ) : get-expr-to-eval ( -- string )
#! Show a page to the user requesting the form to be #! Show a page to the user requesting the form to be
#! evaluated. Return the form as a string. Assumes #! evaluated. Return the form as a string. Assumes
#! an evaluator is on the namestack. #! an evaluator is on the namestack.
[ [
<html> [ <html> [
<head> [
<title> [ "Factor Evaluator" write ] </title>
include-live-updater-js
] </head>
<body> [ <body> [
"Use Alt+E to evaluate, or press 'Evaluate'" paragraph "Use Alt+E to evaluate, or press 'Evaluate'" paragraph
[ [
@ -122,6 +171,7 @@ USE: combinators
[ "stack" get display-stack ] [ "stack" get display-stack ]
[ "history" get display-history ] [ "history" get display-history ]
] horizontal-layout ] horizontal-layout
display-word-see-form
"output" get display-last-output "output" get display-last-output
] </body> ] </body>
] </html> ] </html>