From 70c7c325f94d02af44fcf10ea7daf0dd237d3304 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 19 Jun 2023 13:23:20 -0400 Subject: [PATCH] added session nest dialog --- src/error.rs | 6 ++++++ src/util.rs | 23 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index d33754e..522b238 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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); +} + diff --git a/src/util.rs b/src/util.rs index 69fccbb..be98a32 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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> { let i_sessions = Sessions::get(SESSION_ALL); @@ -22,8 +29,18 @@ pub fn get_sessions() -> Option> { 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", ""); } }