Real-world examples of console input/output operations.
Build a command-line menu for user navigation.
// menu.ifa - Interactive CLI menu
ise show_menu() {
Irosu.fo("\n+---------------------------+");
Irosu.fo("¦ TASK MANAGER v1.0 ¦");
Irosu.fo("¦---------------------------¦");
Irosu.fo("¦ 1. Add new task ¦");
Irosu.fo("¦ 2. List all tasks ¦");
Irosu.fo("¦ 3. Mark task complete ¦");
Irosu.fo("¦ 4. Delete task ¦");
Irosu.fo("¦ 5. Exit ¦");
Irosu.fo("+---------------------------+");
Irosu.so("\nEnter choice (1-5): ");
}
ayanmo running = otito;
ayanmo tasks = [];
nigba (running) {
show_menu();
ayanmo choice = Irosu.ka();
ti (choice == "1") {
Irosu.so("Enter task name: ");
ayanmo name = Irosu.ka();
ayanmo tasks = Ogunda.push(tasks, {"name": name, "done": iro});
Irosu.fo("? Task added!");
} bib?k? ti (choice == "2") {
Irosu.fo("\n=== Your Tasks ===");
ayanmo i = 1;
fun task ninu tasks {
ayanmo status = "";
ti (task["done"]) {
ayanmo status = "[?]";
} bib?k? {
ayanmo status = "[ ]";
}
Irosu.fo(i + ". " + status + " " + task["name"]);
ayanmo i = i + 1;
}
} bib?k? ti (choice == "5") {
Irosu.fo("Goodbye!");
ayanmo running = iro;
}
}
Create a structured logging utility with severity levels.
// logger.ifa - Structured logging
ise log(level, message) {
ayanmo timestamp = Iwori.format(Iwori.now(), "%Y-%m-%d %H:%M:%S");
ayanmo prefix = "";
ti (level == "INFO") {
ayanmo prefix = "[INFO ]";
} bib?k? ti (level == "WARN") {
ayanmo prefix = "[WARN ]";
} bib?k? ti (level == "ERROR") {
ayanmo prefix = "[ERROR]";
} bib?k? ti (level == "DEBUG") {
ayanmo prefix = "[DEBUG]";
}
ayanmo line = timestamp + " " + prefix + " " + message;
ti (level == "ERROR") {
Irosu.kigbe(line); // stderr for errors
} bib?k? {
Irosu.fo(line); // stdout for others
}
}
// Usage
log("INFO", "Application started");
log("DEBUG", "Loading configuration from config.json");
log("WARN", "Config file missing, using defaults");
log("ERROR", "Failed to connect to database");
log("INFO", "Retrying in 5 seconds...");
Output:
2026-01-17 11:30:00 [INFO ] Application started
2026-01-17 11:30:00 [DEBUG] Loading configuration from config.json
2026-01-17 11:30:00 [WARN ] Config file missing, using defaults
2026-01-17 11:30:00 [ERROR] Failed to connect to database
2026-01-17 11:30:00 [INFO ] Retrying in 5 seconds...
Show progress for long-running operations.
// progress.ifa - Progress bar
ise show_progress(current, total, width) {
ayanmo percent = (current * 100) / total;
ayanmo filled = (current * width) / total;
ayanmo bar = "";
ayanmo i = 0;
nigba (i < width) {
ti (i < filled) {
ayanmo bar = bar + "¦";
} bib?k? {
ayanmo bar = bar + "¦";
}
ayanmo i = i + 1;
}
Irosu.so("\r[" + bar + "] " + percent + "%");
}
// Simulate file processing
ayanmo files = 50;
ayanmo processed = 0;
Irosu.fo("Processing files...");
nigba (processed < files) {
show_progress(processed, files, 30);
Oyeku.sleep(50); // Simulate work
ayanmo processed = processed + 1;
}
show_progress(files, files, 30);
Irosu.fo("\n? All files processed!");
// prompt.ifa - Validated input
ise prompt_number(message, min, max) {
ayanmo valid = iro;
ayanmo value = 0;
nigba (!valid) {
Irosu.so(message);
ayanmo input = Irosu.ka();
ayanmo parsed = Ogbe.parse_int(input);
ti (parsed == nil) {
Irosu.fo("? Please enter a valid number.");
} bib?k? ti (parsed < min || parsed > max) {
Irosu.fo("? Must be between " + min + " and " + max);
} bib?k? {
ayanmo valid = otito;
ayanmo value = parsed;
}
}
padap? value;
}
ise prompt_confirm(message) {
Irosu.so(message + " (y/n): ");
ayanmo input = Ika.lowercase(Irosu.ka());
padap? input == "y" || input == "yes";
}
// Usage
ayanmo age = prompt_number("Enter your age (1-120): ", 1, 120);
Irosu.fo("Your age: " + age);
ti (prompt_confirm("Save changes?")) {
Irosu.fo("? Changes saved!");
} bib?k? {
Irosu.fo("? Cancelled.");
}
// table.ifa - Format data as table
ise print_table(headers, rows) {
// Calculate column widths
ayanmo widths = [];
fun h ninu headers {
ayanmo widths = Ogunda.push(widths, Ika.len(h));
}
// Print header
ayanmo header_line = "| ";
ayanmo i = 0;
fun h ninu headers {
ayanmo w = Ogunda.get(widths, i);
ayanmo header_line = header_line + Ika.pad_right(h, w) + " | ";
ayanmo i = i + 1;
}
Irosu.fo(header_line);
// Print separator
ayanmo sep = "|";
fun w ninu widths {
ayanmo sep = sep + Ika.repeat("-", w + 2) + "|";
}
Irosu.fo(sep);
// Print rows
fun row ninu rows {
ayanmo line = "| ";
ayanmo j = 0;
fun cell ninu row {
ayanmo w = Ogunda.get(widths, j);
ayanmo line = line + Ika.pad_right(cell, w) + " | ";
ayanmo j = j + 1;
}
Irosu.fo(line);
}
}
// Usage
ayanmo headers = ["Name", "Role", "Status"];
ayanmo rows = [
["Alice", "Engineer", "Active"],
["Bob", "Designer", "Away"],
["Carol", "Manager", "Active"]
];
print_table(headers, rows);