Create a GUI in Rust with iced – “guissh”
I’ve built a GUI for connecting to remote hosts using SSH. The goal was to learn how to use iced in a real world project called “guissh” – https://youtu.be/uFeOHqomBtI
The “guissh” GUI can be adapted to send and receive commands via SSH, eg to a server, router, firewall, switch or IoT device.
What is iced?
Iced is a cross-platform GUI library focused on simplicity and type-safety. Inspired by Elm
–iced documentation
How to get started and learn from examples?
I got started by adding widgets using the examples from this repo: https://github.com/fogarecious/iced_tutorial/blob/main/README.md
How to create a GUI in Rust with iced :
Add iced with cargo, add some widgets, then you can start adding one or more widgets to run a function that you can match in the “update” function.
iced documentation can be found here:
https://docs.rs/iced/0.12.1/iced/index.html
One of the key things to get started with is to understand how iced uses “update” and “view” functions to do most of the work.
The Design
Below is a simple diagram of what the “guissh” project does.
You’ll need to use SSH2 crate and preferably provide your remote device with the ssh cert from your PC that is running the Rust code (compiled binary executable).
The code
Note! – view and update are iced function names, and in this project “con” is my own function name – I moved it into a separate file called “controller.rs” but you don’t have to use a separate file.
The key part to understand is how the update function works, where the loop checks if the button “connect” has been pressed
The “view” function has an on_press event handler
The view function will then show the output from the “con” function which is called by the update function.
View the code used to create a GUI in Rust with iced:
Summary
We’v taken a look at how the update and view functions work together when we create a GUI in Rust with iced.