はじめに
KScript.UIを使うと、スクリプトからmacOS、Windows、Linuxのネイティブウィンドウを開けます。ウィンドウのレイアウトと状態はスクリプトに記述し、描画はKScriptが行います。他に書くものはありません。Swift、C#、XAML、シェルスクリプトは不要です。
使い始めるには、パッケージをインポートしてWindow { }ブロック(XMLでは<KScript.Window>)を記述します。
<KScript.Window title="Counter" width="320" height="200">
<let name="count" value="0" />
<Text size="32">{$count}</Text>
<Row>
<Button variant="primary" on_click="$count += 1">Add one</Button>
<Button on_click="$count = 0" disabled="$count == 0">Reset</Button>
</Row>
</KScript.Window>import KScript.UI
Window(title: 'Counter', width: 320, height: 200) {
$count = 0
Text(size: 32) "{$count}"
Row {
Button(variant: primary, on_click: $count += 1) "Add one"
Button(on_click: $count = 0, disabled: $count == 0) "Reset"
}
}kscript counter.kscriptでウィンドウが開き、ウィンドウを閉じるとスクリプトが終了します。ウィンドウにはデスクトップ環境が必要です。サーバー上やディスプレイのないSSH接続では、スクリプトはUIエラーで停止します。
samples/life-lab/desktop.kscriptは完全な例です。クリック可能なボード、タイマー、コントロールを備えたライフゲームで、ルールはターミナル版とブラウザ版で共有されています。