本文へ移動
← すべてのサンプル

サンプル 12

Workspace inspect

what is open in the terminal right now — charts, the active

カテゴリ
Workspace:チャートやパネルを読む・変更する
権限
workspace.read
実行する前に
a terminal window (the T0 Lang window running in TTT)
何をするか
none
実行方法
in TTT, open "T0 Lang", open this file, grant workspace.read, Run.
言語
>=0.1.1, <0.2.0
ホスト
>=0.1.3, <0.2.0
必要なもの
workspace >=0.1.2, <0.2.0

ソース

// Purpose: what is open in the terminal right now — charts, the active
// one and what it draws, the symbols on offer, the panels and the panel
// kinds the terminal can open. Changes nothing.
// Category: workspace
// Permissions: workspace.read
// Preconditions: a terminal window (the T0 Lang window running in TTT)
// Side effects: none
// Run: in TTT, open "T0 Lang", open this file, grant workspace.read, Run.

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.3, <0.2.0";
requires "workspace" ">=0.1.2, <0.2.0";

fn main() -> Result<Unit, Error> {
    let charts = workspace.charts();
    print(to_string(charts.len()) + " chart(s) open:");
    for c in charts {
        let marker = if c.active { "*" } else { " " };
        print(marker + " " + c.symbol + " " + c.timeframe + " " + to_string(workspace.indicators(c.chart)?));
    }
    print(to_string(workspace.symbols().len()) + " symbols on offer");
    let panels = workspace.panels();
    print(to_string(panels.len()) + " panel(s):");
    for p in panels {
        let marker = if p.focused { "*" } else { " " };
        print(marker + " " + p.kind + ": " + p.title);
    }
    print("the terminal opens: " + to_string(workspace.panel_kinds()));
    return Ok(());
}