The Konsol: module handles terminal I/O, process control, and utility conversions. Konsol:Print is single-argument — use + or ${} to combine values.
| Call | Effect |
|---|---|
Konsol:Print(expr) |
Print one expression, then newline |
Konsol:Message(expr) |
Alias for Print |
Konsol:Log(expr) |
Print with [LOG] prefix |
Konsol:Input(varName) |
Read a line from stdin into varName |
Konsol:Input("prompt", varName) |
Print prompt then read |
Konsol:Exit() |
Exit with code 0 |
Konsol:Exit(code) |
Exit with given code |
Konsol:Chr(n, outVar) / Konsol:Char(n, outVar) |
ASCII char for code n → outVar |
Konsol:Asc(str, outVar) / Konsol:Ascii(str, outVar) |
ASCII code of first char of str → outVar |
Konsol:IsNumeric(expr, outVar) |
true if value is a valid number → outVar |
Konsol:Delay(ms) |
Sleep for ms milliseconds |
Konsol:Run(cmd, outVar) |
Run shell command, capture stdout → outVar |
Konsol:Input stores a Number if the input looks like one, otherwise a String.
Passing more than one argument to Print, Message, or Log is a syntax error.
Konsol:Print("Hello, world!");
Var:String name;
Konsol:Input("Enter your name: ", name);
Konsol:Print("Hello, " + name);
Var:Number code;
Konsol:Asc("A", code);
Konsol:Print(code); // 65
Var:String ch;
Konsol:Chr(65, ch);
Konsol:Print(ch); // A
Var:Boolean isNum;
Konsol:IsNumeric("42", isNum);
Konsol:Print(isNum); // true
Var:String output;
Konsol:Run("echo hello", output);
Konsol:Print(output); // hello
x// 09_konsol.ks — Konsol module (all non-interactive methods)
// Note: Konsol:Input is interactive; uncomment it to test manually.
Konsol:Print("=== Konsol Module ===");
// Print variants
Konsol:Print("Print: single value");
Konsol:Print("Print: multiple ${"values"} ${42} ${true}");
Konsol:Message("Message: alias for Print");
Konsol:Log("Log: prefixed with [LOG]");
// Escape sequences in strings
Konsol:Print("tab:\there");
Konsol:Print("quote: \"hello\"");
Konsol:Print("backslash: \\");
// Chr — number to ASCII character
Var:String ch;
Konsol:Chr(65, ch);
Konsol:Print("Chr(65) = ${ch}");
Konsol:Chr(97, ch);
Konsol:Print("Chr(97) = ${ch}");
Konsol:Chr(33, ch);
Konsol:Print("Chr(33) = ${ch}");
// Build a string from char codes
Var:String word = "";
Array:New codes[5]:Number;
codes[0] = 72;
codes[1] = 101;
codes[2] = 108;
codes[3] = 108;
codes[4] = 111;
for (Var:Number i = 0; i < 5; i++) {
Konsol:Chr(codes[i], ch);
word = word + ch;
}
Konsol:Print("from codes: ${word}");
// Asc — character to ASCII code
Var:Number code;
Konsol:Asc("A", code);
Konsol:Print("Asc(A) = ${code}");
Konsol:Asc("z", code);
Konsol:Print("Asc(z) = ${code}");
Konsol:Asc("hello", code);
Konsol:Print("Asc(hello) = ${code}");
// IsNumeric
Var:Boolean ok;
Konsol:IsNumeric("123", ok);
Konsol:Print("IsNumeric(123) = ${ok}");
Konsol:IsNumeric("3.14", ok);
Konsol:Print("IsNumeric(3.14) = ${ok}");
Konsol:IsNumeric("-7", ok);
Konsol:Print("IsNumeric(-7) = ${ok}");
Konsol:IsNumeric("abc", ok);
Konsol:Print("IsNumeric(abc) = ${ok}");
Konsol:IsNumeric("12x", ok);
Konsol:Print("IsNumeric(12x) = ${ok}");
// Delay
Konsol:Print("Delay: sleeping 200ms ...");
Konsol:Delay(200);
Konsol:Print("Delay: done");
// Run — execute shell command
Konsol:Print("--- Run ---");
Var:String shellOut;
Konsol:Run("echo hello from shell", shellOut);
Konsol:Print("shell output: ${shellOut}");
// Konsol:Input demo (interactive — uncomment to test):
// Var:String yourName;
// Konsol:Input("Enter your name: ", yourName);
// Konsol:Print("You typed: ${yourName}");