RunestoneInteractive / rs

A New Monorepo structure for Runestone
Other
43 stars 69 forks source link

active code stdin handling is inconsistent #177

Open DaveParillo opened 6 years ago

DaveParillo commented 6 years ago

Runestone include two completely different mechanisms for processing simulated standard input to programs.

  1. The :stdin: option to the active code directive
  2. The :textfield: inline markup.

stdin works great with languages that ship their work off to a jobe server. However, if stdin is used with python, the default value is not used and the text area appears in the popup dialog instead of being added to the code block. Also`input()works, butstdin.readline()`` does not.

It is a bit confusing having two such similar capabilities that do not work consistently across active code languages.

The current stdin does not provide the placement or size flexibility that the textfield markup allows. Also, the styling is not the greatest - it should at least have a space between the prompt and the text field. Not every code block is best served with the prompt: Input for program, which is all the stdin option allows.

Recommendation

This allows book authors to place the text area where they see fit. For a long code block, placing the text area above the code might be a better choice than below it.

.. activecode:: ac-example-java :language: java :interpreterargs: ['-Xrs', '-Xss8m', '-Xmx128m'] :stdin: converter_input

Input for program: :textfield:`converter_input:100:85px` 
~~~~
import java.util.Scanner;

public class TempConv {
    public static void main(String[] args) {
        Double fahr;
         Double cel;
         Scanner in;

         in = new Scanner(System.in);
         System.out.println("Enter the temperature in F: ");
         fahr = in.nextDouble();

         cel = (fahr - 32) * 5.0/9.0;
         System.out.println(fahr + " degrees F is: " + cel + " C");
    }
}
bnmnetp commented 6 years ago

The :textfield: markup is not an option to activecode, it stands alone and its use case was when using Python to do simple DOM manipulations on the web page. It was never meant to be used as stdin only with the document.getElementById function and then getting its value.

I think what you are looking for is the datafile directive for python anyway.

In theory I like the option of wiring up stdin for skulpt to correspond to a DOM element. It would take a bit of experimenting with skulpt to see how to make that happen.

DaveParillo commented 6 years ago

I did not mean to imply that :textfield: is an option to activecode, but simply that there is a fair bit of functional overlap between the two. :stdin: in active code does one very specific thing and it doesn't do it correctly for all active code languages. :textfield: is more general purpose and in theory active code could use a text field to provide a consistent interface to stdin for all activecode languages in addition to all the other dom manipulation capabilities it affords.

Also, since I'm a control freak, I just like having the option to control standard input (placement, prompt, size and default value) - currently :stdin: only allows control over the default value.

I have not looked at datafile at all yet, so my ignorance in that area might be clouding my perceptions on this ticket.

DaveParillo commented 6 years ago

Now that I've had a chance to look at datafile, it seems a nice option or replacement for :stdin: would be to use the id of a datafile directive.