Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu08 committed Nov 18, 2024
1 parent 1ac8e26 commit 1eca854
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
14 changes: 8 additions & 6 deletions src/model/histories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::{command, runner_type};
/// For now, we can define this as tuple like `pub struct Histories(Vec<History>);` 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<History>,
}
Expand Down Expand Up @@ -91,12 +92,13 @@ impl History {
}
}

fn from(histories: (PathBuf, Vec<command::Command>)) -> Self {
Self {
path: histories.0,
executed_commands: histories.1,
}
}
// TODO: 不要そうだったら消す
// fn from(histories: (PathBuf, Vec<command::Command>)) -> Self {
// Self {
// path: histories.0,
// executed_commands: histories.1,
// }
// }

// TODO(#321): remove
#[allow(dead_code)]
Expand Down
38 changes: 20 additions & 18 deletions src/usecase/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Histories> {
// 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<Histories> {
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<command::Command> {
match self.targets_list_state.selected() {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1eca854

Please sign in to comment.