Add read-only mode

Ref: https://github.com/sayanarijit/xplr/issues/22
This commit is contained in:
Arijit Basu 2021-04-19 10:09:46 +05:30 committed by Arijit Basu
parent 4d21a89050
commit 21f87d6a08
3 changed files with 17 additions and 4 deletions

View File

@ -1617,13 +1617,21 @@ impl App {
}
fn call(mut self, command: Command) -> Result<Self> {
self.msg_out.push_back(MsgOut::Call(command));
Ok(self)
if self.config.general.read_only.unwrap_or_default() {
self.log_error("Cannot call command in read-only mode.".into())
} else {
self.msg_out.push_back(MsgOut::Call(command));
Ok(self)
}
}
fn call_silently(mut self, command: Command) -> Result<Self> {
self.msg_out.push_back(MsgOut::CallSilently(command));
Ok(self)
if self.config.general.read_only.unwrap_or_default() {
self.log_error("Cannot call command in read-only mode.".into())
} else {
self.msg_out.push_back(MsgOut::CallSilently(command));
Ok(self)
}
}
fn bash_exec(self, script: String) -> Result<Self> {

View File

@ -280,6 +280,9 @@ pub struct GeneralConfig {
#[serde(default)]
pub show_hidden: Option<bool>,
#[serde(default)]
pub read_only: Option<bool>,
#[serde(default)]
pub cursor: UiElement,
@ -311,6 +314,7 @@ pub struct GeneralConfig {
impl GeneralConfig {
pub fn extend(mut self, other: Self) -> Self {
self.show_hidden = other.show_hidden.or(self.show_hidden);
self.read_only = other.read_only.or(self.read_only);
self.cursor = self.cursor.extend(other.cursor);
self.prompt = self.prompt.extend(other.prompt);
self.logs = self.logs.extend(other.logs);

View File

@ -1,6 +1,7 @@
version: v0.5.0
general:
show_hidden: false
read_only: false
initial_sorting:
- sorter: ByCanonicalIsDir
reverse: true