Compare commits

..

2 commits

Author SHA1 Message Date
65e28327f1 version bump 2023-06-19 13:27:47 -04:00
70c7c325f9 added session nest dialog 2023-06-19 13:23:20 -04:00
3 changed files with 27 additions and 4 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "remux" name = "remux"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -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);
}

View file

@ -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", "");
} }
} }