termux/
lib.rs

1/*  */
2//! # Installation
3//! Download the [Termux:API](https://wiki.termux.com/wiki/Termux:API) add-on.
4//!
5//! You also need to install `termux-api` package. To install Run.
6//! ```sh
7//! pkg i termux-api
8//! ```
9//! Then install the crate
10//! ```sh
11//! cargo add termuxapi
12//! ```
13//!
14//! # Usage
15//! Each command in `termux-api` is mapped to a function by replacing `-` with `::`.
16//! ## Example
17//! The function equivalent of `termux-clipboard-get` would be [termux::clipboard::get]
18//!
19//! All functions return a [Result][std::io::Result].
20//!
21//! # Implemented commands
22//! Not all commands are implemented yet.
23//! This is the list of all implemented commands.
24//! - [termux::api::start]
25//! - [termux::api::stop]
26//! - [termux::audio::info]
27//! - [termux::battery::status]
28//! - [termux::call::log]
29//! - [termux::camera::info]
30//! - [termux::camera::photo]
31//! - [termux::clipboard::set]
32//! - [termux::clipboard::get]
33//!
34//!
35#[cfg(doc)]
36use crate as termux;
37use std::io;
38use std::process::Command;
39//use termux_api_sys as sys;
40//use std::ffi::CString;
41
42pub mod api;
43pub mod audio;
44pub mod battery;
45pub mod call;
46pub mod camera;
47pub mod clipboard;
48
49/*fn run_api_command(args: &[&str]) {
50    let mut args: Vec<_> = args.iter().map(|x| {
51        CString::new(*x).expect("CString::new failed").into_raw();
52    }).collect();
53    sys::run_api_command();
54}*/
55
56fn run_api_cmd(cmd: &str) -> io::Result<String> {
57    let output = Command::new("/data/data/com.termux/files/usr/libexec/termux-api")
58        .arg(cmd)
59        .output()?;
60
61    Ok(String::from_utf8_lossy(&output.stdout).to_string())
62}
63
64fn run_api_cmd_with_args(cmd: &str, args: &[&str]) -> io::Result<String> {
65    let output = Command::new("/data/data/com.termux/files/usr/libexec/termux-api")
66        .arg(cmd)
67        .args(args)
68        .output()?;
69
70    Ok(String::from_utf8_lossy(&output.stdout).to_string())
71}
72
73fn run_cmd(cmd: &str, arg: &str) -> io::Result<()> {
74    let _output = Command::new(cmd).arg(arg).output()?;
75    Ok(())
76}
77
78fn run_cmd_with_args(cmd: &str, args: &[&str]) -> io::Result<()> {
79    let _output = Command::new(cmd).args(args).output()?;
80    Ok(())
81}