Skip to content

Commit

Permalink
Add --preview flag
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite committed Jan 2, 2022
1 parent 7d2b157 commit 203b0a1
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 36 deletions.
192 changes: 192 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ rand = "0.8.4"
chrono = "0.4"
nix = "0.23.1"
logind-dbus = "0.1.1"
clap = { version = "3.0.0", features = ["derive"] }
11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub struct Config {
pub preview: bool
}

impl Default for Config {
fn default() -> Config {
Config {
preview: false
}
}
}
29 changes: 22 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
use log::{error, info};
use std::error::Error;

use log::{error, info};
use clap::{arg, App as ClapApp};

mod graphical_environments;
mod initrcs;
mod pam;
mod ui;
mod config;

use graphical_environments::X;
use ui::{run_app, App};

fn main() -> Result<(), Box<dyn Error>> {
let matches = ClapApp::new("Lemurs")
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.arg(arg!(--preview))
.get_matches();

let mut config = config::Config::default();
config.preview = matches.is_present("preview");

info!("Started");

fern::Dispatch::new()
Expand All @@ -30,15 +43,17 @@ fn main() -> Result<(), Box<dyn Error>> {

info!("Initiated logger");

// Switch to the proper tty
if chvt::chvt(2).is_err() {
error!("Failed to switch TTY");
};
info!("Successfully switched TTY");
if !config.preview {
// Switch to the proper tty
if chvt::chvt(2).is_err() {
error!("Failed to switch TTY");
};
info!("Successfully switched TTY");
}

// Start application
let mut terminal = ui::start()?;
run_app(&mut terminal, App::new())?;
run_app(&mut terminal, App::new(config))?;
ui::stop(terminal)?;

info!("Booting down");
Expand Down
5 changes: 5 additions & 0 deletions src/ui/input_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ impl InputFieldWidget {
self.cursor -= 1;
}

pub fn clear(&mut self) {
self.cursor = 0;
self.content = String::new();
}

pub fn render(
&self,
frame: &mut Frame<impl tui::backend::Backend>,
Expand Down
Loading

0 comments on commit 203b0a1

Please sign in to comment.