File: inline-execute.patch

package info (click to toggle)
rust-bat 0.25.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,096 kB
  • sloc: sh: 255; python: 39; makefile: 14
file content (54 lines) | stat: -rw-r--r-- 1,830 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Description: Inline stripped down version of unavailable dependency execute
Forwarded: not-needed
Author: Blair Noctis <ncts@debian.org>
Last-Update: 2025-03-25
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -141,3 +141,3 @@
 
-[dependencies.execute]
+[disabled.dependencies.execute]
 version = "0.2.13"
@@ -291,3 +291,3 @@
 git = ["git2"]
-lessopen = ["execute"]
+lessopen = [] #["execute"]
 minimal-application = [
--- a/src/lessopen.rs
+++ b/src/lessopen.rs
@@ -10,3 +10,32 @@
 use clircle::{Clircle, Identifier};
-use execute::{shell, Execute};
+//use execute::{shell, Execute};
+use std::process::Command;
+
+trait Execute {
+    fn execute_output(&mut self) -> std::result::Result<std::process::Output, std::io::Error>;
+    fn execute_input_output<D: ?Sized + AsRef<[u8]>>(&mut self, data: &D) -> std::result::Result<std::process::Output, std::io::Error>;
+}
+
+impl Execute for Command {
+    fn execute_output(&mut self) -> std::result::Result<std::process::Output, std::io::Error> {
+        self.spawn()?.wait_with_output()
+    }
+    fn execute_input_output<D: ?Sized + AsRef<[u8]>>(&mut self, data: &D) -> std::result::Result<std::process::Output, std::io::Error> {
+        use std::io::Write;
+        self.stdin(Stdio::piped());
+        let mut child = self.spawn()?;
+        child.stdin.as_mut().unwrap().write_all(data.as_ref())?;
+        child.wait_with_output()
+    }
+}
+
+fn shell<S: AsRef<std::ffi::OsStr>>(cmd: S) -> Command {
+    use std::{ffi::OsString, sync::OnceLock};
+    static SHELL: OnceLock<OsString> = OnceLock::new();
+    let shell = SHELL.get_or_init(|| env::var_os("SHELL").unwrap_or_else(|| OsString::from("sh")));
+    let mut command = Command::new(shell);
+    command.arg("-c");
+    command.arg(cmd);
+    command
+}