From 1eca854a59cce0b18d108618773c2c3b3dc1ec6e Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Tue, 19 Nov 2024 00:42:22 +0900 Subject: [PATCH] wip --- src/model/histories.rs | 14 ++++++++------ src/usecase/tui/app.rs | 38 ++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/model/histories.rs b/src/model/histories.rs index 3b65b12..b007566 100644 --- a/src/model/histories.rs +++ b/src/model/histories.rs @@ -7,6 +7,7 @@ use super::{command, runner_type}; /// For now, we can define this as tuple like `pub struct Histories(Vec);` but we don't. /// We respect that we can add some fields in the future easily. #[derive(Clone, PartialEq, Debug)] +// TODO: 削除する? pub struct Histories { pub histories: Vec, } @@ -91,12 +92,13 @@ impl History { } } - fn from(histories: (PathBuf, Vec)) -> Self { - Self { - path: histories.0, - executed_commands: histories.1, - } - } + // TODO: 不要そうだったら消す + // fn from(histories: (PathBuf, Vec)) -> Self { + // Self { + // path: histories.0, + // executed_commands: histories.1, + // } + // } // TODO(#321): remove #[allow(dead_code)] diff --git a/src/usecase/tui/app.rs b/src/usecase/tui/app.rs index 596ed2d..69fa237 100644 --- a/src/usecase/tui/app.rs +++ b/src/usecase/tui/app.rs @@ -396,15 +396,17 @@ impl SelectTargetState<'_> { // TODO(#321): comment in this method // TODO: This method should return Result when it fails. - // pub fn append_history(&self, command: &str) -> Option { - // match &self.histories { - // Some(histories) => { - // histories.append(&self.runners[0].path(), command) - // // TODO(#321): For now, it is &self.runners[0] to pass the compilation, but it should be taken from runner::Command::path() - // } - // _ => None, - // } - // } + pub fn append_history(&self, command: &command::Command) -> Option { + TODO: そのpathのhistoryをgetする + TODO: そのpathのhistoryがない場合はここで初期化して追加する + match &self.histories { + Some(histories) => { + histories.append(&self.runners[0].path(), command) + // TODO(#321): For now, it is &self.runners[0] to pass the compilation, but it should be taken from runner::Command::path() + } + _ => None, + } + } fn selected_target(&self) -> Option { match self.targets_list_state.selected() { @@ -585,18 +587,18 @@ impl SelectTargetState<'_> { self.search_text_area.0.input(key_event); } - fn store_history(&mut self, _command: &command::Command) { - // TODO(#321): implement when history function is implemented + fn store_history(&mut self, command: &command::Command) { // NOTE: self.get_selected_target should be called before self.append_history. // Because self.histories_list_state.selected keeps the selected index of the history list // before update. - // if let Some(h) = self.append_history(command) { - // self.histories = Some(h) - // }; - // if let (Some((dir, file_name)), Some(h)) = (history_file_path(), &self.histories) { - // // TODO: handle error - // let _ = toml::store_history(dir, file_name, h.to_tuple()); - // }; + // TODO(#321): implement when history function is implemented + if let Some(h) = self.append_history(command) { + self.histories = Some(h) + }; + if let (Some((dir, file_name)), Some(h)) = (history_file_path(), &self.histories) { + // TODO: handle error + let _ = toml::store_history(dir, file_name, h.to_tuple()); + }; } fn reset_selection(&mut self) {