forked from bonsai/harakit
.editorconfig: fixed utf8 issue
This commit is contained in:
parent
cbe8f5f8e8
commit
d20a1da6f8
@ -1,7 +1,7 @@
|
|||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
charset = utf8
|
charset = utf-8
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
76
src/fop.rs
Normal file
76
src/fop.rs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU Affero General Public License as published by the Free
|
||||||
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
env::args,
|
||||||
|
io::{ Read, stdin, Write },
|
||||||
|
process::{ Command, exit, Stdio },
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let argv = args().collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let index = match argv.get(1) {
|
||||||
|
Some(i) => {
|
||||||
|
i.parse::<usize>().unwrap_or_else(|_| {
|
||||||
|
eprintln!("{}: {}: Not an integer.", argv[0], i);
|
||||||
|
exit(1);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
eprintln!("Usage: {} index command args...", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut buf = String::new();
|
||||||
|
stdin().read_to_string(&mut buf).unwrap();
|
||||||
|
let mut fields = buf.split('␞').collect::<Vec<&str>>();
|
||||||
|
|
||||||
|
argv.get(2).unwrap_or_else(|| {
|
||||||
|
eprintln!("Usage: {} index command args...", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
let opts = argv.iter().clone().skip(3).collect::<Vec<&String>>();
|
||||||
|
|
||||||
|
let mut spawned = Command::new(argv.get(2).unwrap())
|
||||||
|
.args(opts)
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let field = fields.get(index).unwrap_or_else(|| {
|
||||||
|
eprintln!("{}: {}: No such index in input.", argv[0], index.to_string());
|
||||||
|
exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(mut child_stdin) = spawned.stdin.take() {
|
||||||
|
child_stdin.write_all(field.as_bytes()).unwrap();
|
||||||
|
drop(child_stdin);
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = spawned.wait_with_output().unwrap();
|
||||||
|
|
||||||
|
let new_field = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
|
fields[index] = &new_field;
|
||||||
|
|
||||||
|
print!("{}", fields.join("␞"));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user