Skip to content
← All examples

Example 15

Capabilities

what this terminal offers programs right now, contract by

Category
Workspace: reads or changes charts and panels
Permissions
none (it describes; it grants nothing)
Before you run it
running inside TTT (the CLI has no host)
What it does
none
How to run it
in TTT, open "T0 Lang", open this file, Run. Then grant something
Language
>=0.1.1, <0.2.0
Host
>=0.1.3, <0.2.0
Needs
capabilities >=0.1.0, <0.2.0

Source

// Purpose: what this terminal offers programs right now, contract by
// contract: what can run here (available) and what this session has
// granted (authorized) — two different things.
// Category: workspace
// Permissions: none (it describes; it grants nothing)
// Preconditions: running inside TTT (the CLI has no host)
// Side effects: none
// Run: in TTT, open "T0 Lang", open this file, Run. Then grant something
// and Run again: the "granted" counts change, the "available" ones do not.

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.3, <0.2.0";
requires "capabilities" ">=0.1.0, <0.2.0";
import std.list;

fn main() {
    let all = capabilities.operations();
    let mut contracts: List<String> = [];
    for op in all {
        if !list.contains(contracts, op.contract) {
            contracts.push(op.contract);
        }
    }
    for name in contracts {
        let mut total = 0;
        let mut available = 0;
        let mut usable = 0;
        let mut version = "";
        for op in all {
            if op.contract == name {
                total = total + 1;
                version = op.version;
                if op.available {
                    available = available + 1;
                    if op.granted {
                        usable = usable + 1;
                    }
                }
            }
        }
        print(name + " " + version + ": " + to_string(total) + " operations, " + to_string(available) + " available here, " + to_string(usable) + " of those granted");
    }
    for op in all {
        match op.why {
            Some(why) => print("  not here: " + op.contract + "." + op.operation + " (" + why + ")"),
            None => {}
        }
    }
}