added session nest dialog
This commit is contained in:
parent
044736b535
commit
70c7c325f9
2 changed files with 26 additions and 3 deletions
|
@ -30,3 +30,9 @@ pub fn missing_target() {
|
||||||
exit(4);
|
exit(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// user declined nesting dialog
|
||||||
|
pub fn nest_declined() {
|
||||||
|
println!("remux: session nesting declined by user");
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
23
src/util.rs
23
src/util.rs
|
@ -1,5 +1,10 @@
|
||||||
use std::{
|
use std::{
|
||||||
env::var,
|
env::{ set_var, var },
|
||||||
|
io::{
|
||||||
|
self,
|
||||||
|
|
||||||
|
Read, Write
|
||||||
|
},
|
||||||
process::exit
|
process::exit
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,6 +13,8 @@ use tmux_interface::{
|
||||||
variables::session::session::SESSION_ALL
|
variables::session::session::SESSION_ALL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::error;
|
||||||
|
|
||||||
/// return a Vec of all sessions or None
|
/// return a Vec of all sessions or None
|
||||||
pub fn get_sessions() -> Option<Vec<Session>> {
|
pub fn get_sessions() -> Option<Vec<Session>> {
|
||||||
let i_sessions = Sessions::get(SESSION_ALL);
|
let i_sessions = Sessions::get(SESSION_ALL);
|
||||||
|
@ -22,8 +29,18 @@ pub fn get_sessions() -> Option<Vec<Session>> {
|
||||||
pub fn prevent_nest() {
|
pub fn prevent_nest() {
|
||||||
let tmux = var("TMUX").ok();
|
let tmux = var("TMUX").ok();
|
||||||
if tmux.is_some() && tmux.unwrap() != "" {
|
if tmux.is_some() && tmux.unwrap() != "" {
|
||||||
println!("Sessions should be nested with care; unset TMUX to allow.");
|
// ask the user if they want to nest (default: no)
|
||||||
exit(1);
|
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", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue