added session nest dialog

This commit is contained in:
Valerie Wolfe 2023-06-19 13:23:20 -04:00
parent 044736b535
commit 70c7c325f9
2 changed files with 26 additions and 3 deletions

View file

@ -30,3 +30,9 @@ pub fn missing_target() {
exit(4);
}
/// user declined nesting dialog
pub fn nest_declined() {
println!("remux: session nesting declined by user");
exit(5);
}

View file

@ -1,5 +1,10 @@
use std::{
env::var,
env::{ set_var, var },
io::{
self,
Read, Write
},
process::exit
};
@ -8,6 +13,8 @@ use tmux_interface::{
variables::session::session::SESSION_ALL
};
use crate::error;
/// return a Vec of all sessions or None
pub fn get_sessions() -> Option<Vec<Session>> {
let i_sessions = Sessions::get(SESSION_ALL);
@ -22,8 +29,18 @@ pub fn get_sessions() -> Option<Vec<Session>> {
pub fn prevent_nest() {
let tmux = var("TMUX").ok();
if tmux.is_some() && tmux.unwrap() != "" {
println!("Sessions should be nested with care; unset TMUX to allow.");
exit(1);
// ask the user if they want to nest (default: no)
print!("Are you sure you want to nest sessions? (y/N) ");
let _ = io::stdout().flush();
let mut input = [0];
let _ = io::stdin().read(&mut input);
match input[0] as char {
'y' | 'Y'
=> {},
_ => error::nest_declined()
}
set_var("TMUX", "");
}
}