<< lines Console %onprompt >>

Scilab Help >> Console > mode

mode

sets or queries the mode echoing Scilab instructions in the console

Syntax

mode(k)
k = mode()

Arguments

k

integer from -1 to 6: chosen or current execution / echoing mode.

Description

mode(k) allows to choose how informations are displayed in the console during the execution of Scilab instructions. If these instructions include a mode one, following ones in the same environment are echoed according to the new mode. A semicolon appended to any instruction always cancels the display of its result, whatever is the current execution mode.

Contexts
mode(..) and other instructions can be used and executed in various contexts:
Features
mode # -10 1 2 3 4 6
Displays instructions [a] C C C S C C S C S C S K
Displays results [b] alwaysalwaysalwaysalwaysalwaysalways
Step by step [s] S F K S F T K
Compact [c] C+++++SFT +CK++ SFT+S+
Comments [d] [e] [f] [g][h][h,i]
Comments
[a]: In normal modes, instructions are displayed with the --> heading prompt. In step-by-step modes, >> is used instead.
[b]: provided that no semicolon is appended.
[c]: "+" means: no extra blank line after results. "++" means: no extra blank line neither after completed instructions, nor after results.
[d]: Default silent mode in functions and with execstr().
[e]: mode(5) is equivalent to mode(1) but must not be used.
[f]: Default mode in the console.
[g]: Default exec() mode.
[h]:
  • Any comment // is displayed without prompting and being stepped.
  • Some parasitic --> prompts and extra blank lines may be sometimes displayed (bug).
  • A callback is always made of a unique string of instructions, as if they were specified and run on a single row. Therefore, both available stepping execution modes are activable but useless in any callback.
[i]: mode(7) does the same but must not be used.
[s]: The step-by-step mode stops after each line of instruction(s) and waits for the user pressing the <enter> or p<enter> keys to go on. Entering p enters the pause mode. These modes may be used for instance in demos, or as a raw debugging mode.

The mode in the calling environment is never changed after using mode(..) in a called function, in an executed script.sce or as an execstr() input, after the execution is completed and returns. When mode(k) is used in a callback that is executed, it becomes and remains the actual echoing mode in the console after the end of the callback.
Output intentionnally displayed by functions like disp() or mprinf() are never cancelled, even with mode(-1).
mode(5), mode(7), and other unregistered values may be accepted but should not be used: they could be removed or redefined in the future.

Examples

In a function():

function example_mode(level_mode)
   disp(mode());
   mode(level_mode)
   a = 3
endfunction

mode(2)
example_mode(0)
mode()
example_mode(1)
example_mode(2)

With exec(script, mode):

ins = [
    "mprintf(""Default execution mode: %d\n"", mode())"
    "mode(i)"
    "mprintf(""New active mode: %d\n"", mode())"
    "// A new comment"
    "a = rand(2,4)"
    "b = %pi;"
    "c = %s;"
    ];
fn = TMPDIR + "\test_mode.sce";
mputl(ins, fn);
//
mode(2)
i = 1;
exec(fn)
mode()
exec(fn, 0)
i = 3; // instructions are displayed
exec(fn, 3)
i = 4; // displayed instructions + stepped mode. "p<enter>" enters the paused mode
exec(fn, 4)

With execstr():

ins = [
    "mprintf(""Default execution mode: %d\n"", mode())"
    "mode(1)        // Entering the compact mode"
    "mprintf(""New active mode: %d\n"", mode())"
    "a = rand(2,4)"
    "b = 1"
    "c = %pi"
    ];
mode(2)
execstr(ins)
mode()       // The initial mode is restored

In a callback (here a menu):

mode(2)
uimenu("parent",0,"Label","mode_test",..
       "callback", "disp(mode()); mode(1); a = rand(2,4), pwd(),");
// Click on the "mode_test" menu and see what is displayed in the console
mode()
delmenu mode_test

See also

History

VersionDescription
6.0
  • mode(4) is now stepped and can be paused, in scripts as well as in functions.
  • For/in scripts, mode(4) now displays each line of instructions, and displays results in a compact way. It can be used for demos.
  • Callbacks were always executed in silent mode(-1). They are now executed by default in the current mode().

Report an issue
<< lines Console %onprompt >>