summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/config/mod.rs
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2020-06-05 01:10:31 +0300
committerGitHub <noreply@github.com>2020-06-05 01:10:31 +0300
commitf99220f01553c6c9d36e1f4ce01c007f4d4d4cb5 (patch)
treea61843b8ffe5fc25cc3a35157bc1a4346f37d40b /alacritty_terminal/src/config/mod.rs
parent1e32e5a5154a2e765ca0b3ab8e50e4c01bbe5d18 (diff)
downloadalacritty-f99220f01553c6c9d36e1f4ce01c007f4d4d4cb5.tar.gz
alacritty-f99220f01553c6c9d36e1f4ce01c007f4d4d4cb5.zip
Refactor Shell, Command, and Launcher to share impl
Diffstat (limited to 'alacritty_terminal/src/config/mod.rs')
-rw-r--r--alacritty_terminal/src/config/mod.rs64
1 files changed, 22 insertions, 42 deletions
diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs
index de72d3e2..b3f13492 100644
--- a/alacritty_terminal/src/config/mod.rs
+++ b/alacritty_terminal/src/config/mod.rs
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Display;
use std::path::PathBuf;
@@ -78,8 +77,8 @@ pub struct Config<T> {
pub selection: Selection,
/// Path to a shell program to run on startup.
- #[serde(default, deserialize_with = "from_string_or_deserialize")]
- pub shell: Option<Shell<'static>>,
+ #[serde(default, deserialize_with = "failure_default")]
+ pub shell: Option<Program>,
/// Path where config was loaded from.
#[serde(default, deserialize_with = "failure_default")]
@@ -286,33 +285,30 @@ where
.unwrap_or_else(|_| Percentage::new(DEFAULT_CURSOR_THICKNESS)))
}
-#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
-pub struct Shell<'a> {
- pub program: Cow<'a, str>,
-
- #[serde(default, deserialize_with = "failure_default")]
- pub args: Vec<String>,
+#[serde(untagged)]
+#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
+pub enum Program {
+ Just(String),
+ WithArgs {
+ program: String,
+ #[serde(default, deserialize_with = "failure_default")]
+ args: Vec<String>,
+ },
}
-impl<'a> Shell<'a> {
- pub fn new<S>(program: S) -> Shell<'a>
- where
- S: Into<Cow<'a, str>>,
- {
- Shell { program: program.into(), args: Vec::new() }
- }
-
- pub fn new_with_args<S>(program: S, args: Vec<String>) -> Shell<'a>
- where
- S: Into<Cow<'a, str>>,
- {
- Shell { program: program.into(), args }
+impl Program {
+ pub fn program(&self) -> &str {
+ match self {
+ Program::Just(program) => program,
+ Program::WithArgs { program, .. } => program,
+ }
}
-}
-impl FromString for Option<Shell<'_>> {
- fn from(input: String) -> Self {
- Some(Shell::new(input))
+ pub fn args(&self) -> &[String] {
+ match self {
+ Program::Just(_) => &[],
+ Program::WithArgs { args, .. } => args,
+ }
}
}
@@ -395,19 +391,3 @@ where
value => Some(T::deserialize(value).unwrap_or_else(fallback_default)),
})
}
-
-pub fn from_string_or_deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error>
-where
- D: Deserializer<'de>,
- T: Deserialize<'de> + FromString + Default,
-{
- Ok(match Value::deserialize(deserializer)? {
- Value::String(value) => T::from(value),
- value => T::deserialize(value).unwrap_or_else(fallback_default),
- })
-}
-
-// Used over From<String>, to allow implementation for foreign types.
-pub trait FromString {
- fn from(input: String) -> Self;
-}