JSAV Pseudo-code API, phase 1

1 reply [Last post]
ville
ville's picture
Offline
White BeltYellow BeltGreen BeltRed BeltBlack Belt
Joined: 2009-05-28
Posts:
Points: 559

I’ve started working on the pseudocode API and wanted to get your input on it before I implement it. I think it can be kept relatively simple (for now) since I can’t come up with use cases where one should do something other than show/hide, (un)highlight, or change the styling of the lines of code. I want to follow the same naming conventions as rest of JSAV, so here’s what I’m thinking:

  • Pseudocode can be initialized with jsav.code(codeLines, [options]). codeLines can either be an array (items in array become lines in code) or a string (split on newlines ‘\n’ and then made into lines). At least option to control whether line numbers are shown is needed besides the "normal" JSAV structure options (like left/top for positioning, etc)
  • Another way to initialize it from a url of a file containing the code is with jsav.code(options) with an option url that can be a relative or absolute url. However, same origin policy restrictions in browsers restrict where the code can loaded.
  • Lines can be (un)highlighted with code.highlight(indices). Like for arrays, indices can be a number, an array of numbers, or a filter function. Function isHighlight(index) can be used to check whether a line is highlighted.
  • All lines can be made visible/invisible with code.show() and code.hide()
  • Single lines can be made visible/invisible with code.show(indices) and code.hide(indices). Indices parameter like for highlight/unhighlight.
  • Styling of lines can be changed with code.css(indices, cssProps). Parameters work like for for the array css() function.
  • Another common use for the pseudocode is to highlight the current and previous lines like in a visual debugger. For this, I’ve planned function code.setCurrentLine(index) which will highlight the line at given index and, if there already was a line set as current, that will be highlighted with a different color to indicate the previous line. Parameter index should always be a number.

What do you think of this? Any other functionality that is needed at this point?

Ville Karavirta, Aalto University, http://villekaravirta.com/

shaffer
shaffer's picture
Offline
White BeltYellow BeltGreen BeltRed BeltBlack Belt
Joined: 2009-05-28
Posts:
Points: 2009
Re: JSAV Pseudo-code API, phase 1

Thanks! This addresses the issue that I raised with you earlier about reading code from a file. Once I work out the syntax for pulling sections of code for display in the modules, we can talk about whether that can be used in this context as well.