aboutsummaryrefslogtreecommitdiff
path: root/src/consulter.rs
blob: 7c7bca795f11cbe81e2d6219fc8eb23564035590 (plain)
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
use std::fs::File;
use std::io::{Error, ErrorKind, Result, Write};
use std::process::Command;

use crate::game::*;
use crate::gui::*;
use crate::parser::*;

const FILE_NAME: &str = "/tmp/takwrap_ptn_consult.ptn";

pub fn consult_next_action(game: &Game, proc: &str) -> Result<GUIResult> {
    let file = File::create(FILE_NAME)?;

    write!(&file, "{}", game)?;

    let output = Command::new(proc).args(&[FILE_NAME]).output()?;

    match String::from_utf8(output.stdout) {
        Err(e) => Err(Error::new(ErrorKind::InvalidData, e)),
        Ok(raw) => Ok(GUIResult::Raw(raw)),
        // Ok(string) => match parse_action(game.query_stone_owner(), &string.trim()) {
        //     Err(string) => Err(Error::new(ErrorKind::InvalidData, string)),
        //     Ok(action) => GUIResult::Selected(action),
        // },
    }
}