Add an example using bash and jq

This commit is contained in:
Olivier Goffart 2021-09-30 17:35:17 +02:00
parent d0f953f0e5
commit 672c95db42
2 changed files with 50 additions and 0 deletions

14
examples/bash/README.md Normal file
View file

@ -0,0 +1,14 @@
# SixtyFPS Bash example
This shows how to use `sixtyfps-viewer` to display dialog from a bash script.
This assume that the `sixtyfps-viewer` tool is in patch. This can be achieved with cargo install.
(use the `--path tools/viewer` option to install it from the current repository.)
```bash
cargo install sixtyfps-viewer
```
The examples also assume that [`jq`](https://stedolan.github.io/jq/) is in the path
* `simple_input.sh`: shows how to query a few parameter with bash

36
examples/bash/simple_input.sh Executable file
View file

@ -0,0 +1,36 @@
#!/bin/bash -e
# LICENSE BEGIN
# This file is part of the SixtyFPS Project -- https://sixtyfps.io
# Copyright (c) 2021 Olivier Goffart <olivier.goffart@sixtyfps.io>
# Copyright (c) 2021 Simon Hausmann <simon.hausmann@sixtyfps.io>
#
# SPDX-License-Identifier: GPL-3.0-only
# This file is also available under commercial licensing terms.
# Please contact info@sixtyfps.io for more information.
# LICENSE END
OUTPUT=$(sixtyfps-viewer - --save-data - << EOF
import { StandardButton, GridBox, LineEdit } from "sixtyfps_widgets.60";
_ := Dialog {
property name <=> name-le.text;
property address <=> address-le.text;
StandardButton { kind: ok; }
StandardButton { kind: cancel; }
preferred-width: 300px;
GridBox {
Row {
Text { text: "Enter Your name"; }
name-le := LineEdit { }
}
Row {
Text { text: "Address"; }
address-le := LineEdit { }
}
}
}
EOF
)
NAME=$(jq -r ".name" <<< "$OUTPUT")
ADDRESS=$(jq -r ".address" <<< "$OUTPUT")
echo "Your name is $NAME and you live in $ADDRESS!"