summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <julian.hurst92@gmail.com>2022-07-21 20:17:15 +0200
committerJulian Hurst <julian.hurst92@gmail.com>2022-07-21 20:17:15 +0200
commit58620679e7f59cbf4a7f559ca9a78a6117d6c0ba (patch)
tree30c815fd173e4bbed95253f90b0ea622f3f1218f
parent84c4042ac883ac5bdc0e281cbdceae864ca6eb75 (diff)
downloadimp-prompt.tar.gz
Add prompt feature when -p flag is usedprompt
-rw-r--r--imp.ha52
1 files changed, 52 insertions, 0 deletions
diff --git a/imp.ha b/imp.ha
index 1a5f7a4..980acb9 100644
--- a/imp.ha
+++ b/imp.ha
@@ -6,6 +6,7 @@ use io;
use strings;
use bufio;
use format::ini;
+use strio;
let verbose: bool = false;
@@ -115,6 +116,19 @@ export fn main() void = {
fmt::println(acc.name)!;
};
} else {
+ if (displaypass) {
+ let st = strio::dynamic();
+ defer io::close(&st)!;
+ for (let i = 0z; i < len(accounts); i += 1) {
+ const facc = format(accounts[i]);
+ defer free(facc);
+ strio::concat(&st, "key ", facc, "\n")!;
+ };
+ strio::concat(&st, "prompt disclose")!;
+ if (!prompt(strio::string(&st))!) {
+ fmt::fatal("Request denied");
+ };
+ };
for (let i = 0z; i < len(accounts); i += 1) {
let acc = accounts[i];
fmt::printfln("name\t{}", acc.name)!;
@@ -190,6 +204,44 @@ fn isfiltered(acc: account, f: filter) bool = {
return false;
};
+fn prompt(in: str) (bool | os::exec::error | io::error) = {
+ let cmd = os::exec::cmd("hiprompt-gtk")?;
+ let pipe_stdin = exec::pipe();
+ let pipe_stdout = exec::pipe();
+
+ os::exec::addfile(&cmd, os::stdin_file, pipe_stdin.0);
+ os::exec::addfile(&cmd, os::stdout_file, pipe_stdout.1);
+
+ fmt::fprintln(os::stderr, "version")!;
+ fmt::fprintln(os::stderr, in)!;
+ let proc = os::exec::start(&cmd)?;
+ //io::writeall(pipe_stdin.1, strings::toutf8(in))?;
+ io::close(pipe_stdin.0)?;
+ io::close(pipe_stdout.0)?;
+ io::close(pipe_stdout.1)!;
+
+ fmt::fprintln(pipe_stdin.1, in)?;
+ io::close(pipe_stdin.1)!;
+ //io::close(pipe_stderr.0)?;
+ //io::close(pipe_stderr.1)!;
+
+ let status = os::exec::wait(&proc)?;
+
+ match (os::exec::check(&status)) {
+ case let e: !os::exec::exit_status =>
+ fmt::fprintln(os::stderr, exec::exitstr(e))!;
+ return false;
+ case void =>
+ return true;
+ };
+};
+
+// Return needs to be freed
+fn format(acc: account) str = {
+ //return fmt::asprintf("url={} user={} pass!={}", acc.url, acc.user, acc.pass);
+ return fmt::asprintf("user={} pass!={}", acc.user, acc.pass);
+};
+
fn accs_filter(accounts: []account, accfilter: filter) []account = {
if (isemptyfilter(accfilter)) {
return accounts;