Added show project name on launchpad functionnality and updated the README accordingly

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2022-06-03 10:11:12 +02:00
parent 5ad765fcae
commit de1e93a64f
No known key found for this signature in database
GPG Key ID: 0C87282F76E61283
2 changed files with 48 additions and 21 deletions

View File

@ -18,6 +18,30 @@ I used mainly two libraries for this project:
These two libraries are maintained at the moment this README is being written.
## Using
### Open associated project
Clicking on a tile opens the corresponding web page for the project linked to
this tile.
### Retry/create pipeline for project
Clicking on the `A` button will engage the `restart` mode. As long as it is
lit up, the mode is engaged.
If you click on a tile while the `A` button is lit up, it will retry or create a
new pipeline for this project and for this ref. You can disengage the mode by
pressing again the `A` button.
### Show project name on launchpad
Clicking on the `B` button will engage the `show text` mode. As long as it is
lit up, the mode is engaged.
If you click on a tile while the `B` button is lit up, it will show the project
name. You can disengage the mode by pressing again the `B` button.
## Building
As any other `cargo` project, it can be built with a simple command:
@ -41,12 +65,6 @@ in the current working directory. An example configuration file is provided,
The abs\_x and abs\_y coordinate are defined using the top-left grid tile as
the origin.
Clicking on a tile opens the corresponding web page for the project linked to
this tile. Clicking on the `A` button will light it up, it is the restart button.
If you click on a tile with the `A` button lit up, it will retry or create a
new pipeline for this project and for this ref. You can disengage the restart
mode by pressing again the `A` button.
## Limitations
This project has some limitations right now, and some of them will be fixed:

View File

@ -4,34 +4,38 @@ use log::{trace, debug, warn};
use crate::{config_manager::Config, gitlab_controller::retry_pipeline};
const RESTART_BUTTON: Button = Button::GridButton { x: 8, y: 0 }; // A BUTTON
const SHOW_TEXT_BUTTON: Button = Button::GridButton { x: 8, y: 1 }; // B BUTTON
fn engage_restart(output: &mut Output) {
trace!("Engaging restart mode.");
output.set_button(RESTART_BUTTON, Color::DIM_GREEN, DoubleBufferingBehavior::Copy).unwrap();
fn set_restart_light(output: &mut Output, status: bool) {
trace!("{} restart mode.", if status { "Engaged" } else { "Disengaged" });
output.set_button(RESTART_BUTTON,
if status { Color::DIM_GREEN } else { Color::OFF },
DoubleBufferingBehavior::Copy).unwrap();
}
fn disengage_restart(output: &mut Output) {
trace!("Disengaging restart mode.");
output.set_button(RESTART_BUTTON, Color::OFF, DoubleBufferingBehavior::Copy).unwrap();
fn set_show_text_light(output: &mut Output, status: bool) {
trace!("{} show text mode.", if status { "Engaged" } else { "Disengaged" });
output.set_button(SHOW_TEXT_BUTTON,
if status { Color::DIM_GREEN } else { Color::OFF },
DoubleBufferingBehavior::Copy).unwrap();
}
fn running_thread(config: Config) {
trace!("Starting a thread dedicated to the Launchpad input.");
let mut output = Output::guess().unwrap();
let input = Input::guess_polling().unwrap();
let mut restart = false;
let (mut restart, mut show) = (false, false);
for msg in input.iter() {
debug!("Got message from Launchpad: {:?}.", msg);
if let Message::Release { button } = msg {
if button == RESTART_BUTTON {
debug!("Restart button has been pressed.");
if !restart {
restart = true;
engage_restart(&mut output);
} else {
restart = false;
disengage_restart(&mut output);
}
restart = !restart;
set_restart_light(&mut output, restart);
} else if button == SHOW_TEXT_BUTTON {
debug!("Show text button has been pressed.");
show = !show;
set_show_text_light(&mut output, show);
} else if button.abs_x() != 8 {
debug!("A project tile has been pressed.");
let project = config.projects.iter()
@ -47,7 +51,12 @@ fn running_thread(config: Config) {
project);
restart = false;
retry_pipeline(config.host.as_str(), config.token.as_str(), project);
disengage_restart(&mut output);
set_restart_light(&mut output, restart);
} else if show {
debug!("Showing project name on launchpad for project {:?}.", project);
show = false;
set_show_text_light(&mut output, show);
output.scroll_text(project.name.as_bytes(), Color::RED, false).unwrap();
} else {
let url = format!("https://{}/{}", config.host, project.name);
debug!("Restart mode isn't engaged. Trying to open project {:?} in browser with URL {}.",