Skip to content

Commit

Permalink
keymap: renamed Select.. to NavigateTo.. for clear naming
Browse files Browse the repository at this point in the history
Signed-off-by: aserowy <serowy@hotmail.com>
  • Loading branch information
aserowy committed Feb 19, 2024
1 parent b8db440 commit 00768ec
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 108 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In every mode `esc` switches to the next 'level' mode. The order is:

navigation < normal < insert

Exceptions to this order is the command mode. Leaving this mode will restore the
Exception to this order is the command mode. Leaving this mode will restore the
previous one.

When transition from normal to navigation all changes to the filesystem will get
Expand Down Expand Up @@ -70,14 +70,12 @@ pass them to the relevant components.
The frontend follows an elm architecture with one exception: The model is
mutable and will not get created every update.

frontend.rs holds the lifecycle of the tui. It starts an event stream to
It holds the lifecycle of the tui. It starts an event stream to
enable non lockable operations. This stream is implemented in event.rs and
translates multiple event emitter like terminal interaction with crossterm into
AppEvents.
messages.

layout.rs defines the overall app layout, which is used by all view functions.

The modules model, update and view represent the elm philosophy. Messages
The modules model, update and view represent parts of the elm philosophy. Messages
are defined in yeet-keymap to prevent cycling dependencies.

### yeet-keymap
Expand Down
2 changes: 1 addition & 1 deletion yeet-frontend/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Emitter {
let tasks = TaskManager::new(task_sender);
tokio::spawn(async move {
internal_sender
.send(vec![Message::SelectPath(initial_path)])
.send(vec![Message::NavigateToPath(initial_path)])
.await
.expect("Failed to send message");

Expand Down
190 changes: 95 additions & 95 deletions yeet-frontend/src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn update(
settings,
model,
layout,
&Message::SelectPath(model.current.path.clone()),
&Message::NavigateToPath(model.current.path.clone()),
),
"histopt" => Some(vec![RenderAction::Post(PostRenderAction::Task(
Task::OptimizeHistory,
Expand Down Expand Up @@ -202,6 +202,100 @@ pub fn update(
model.key_sequence = sequence.clone();
None
}
Message::NavigateToCurrent => {
if model.mode != Mode::Navigation {
None
} else if let Some(mut actions) = path::set_current_to_selected(model) {
let current_content = model.current.buffer.lines.clone();

buffer::set_content(
&model.mode,
&mut model.current.buffer,
model.preview.buffer.lines.clone(),
);
current::update(model, layout, None);

history::set_cursor_index(
&model.current.path,
&model.history,
&mut model.current.buffer,
);

if let Some(preview_actions) = path::set_preview_to_selected(model, false, true) {
actions.extend(preview_actions);
}
model.preview.buffer.lines.clear();
preview::update(model, layout, None);

buffer::set_content(&model.mode, &mut model.parent.buffer, current_content);
parent::update(model, layout, None);

model.history.add(&model.current.path);

Some(actions)
} else {
None
}
}
Message::NavigateToParent => {
if model.mode != Mode::Navigation {
None
} else if let Some(mut actions) = path::set_current_to_parent(model) {
let current_content = model.current.buffer.lines.clone();

buffer::set_content(
&model.mode,
&mut model.current.buffer,
model.parent.buffer.lines.clone(),
);
current::update(model, layout, None);

history::set_cursor_index(
&model.current.path,
&model.history,
&mut model.current.buffer,
);

if let Some(preview_actions) = path::set_preview_to_selected(model, true, false) {
actions.extend(preview_actions);
}
buffer::set_content(&model.mode, &mut model.preview.buffer, current_content);
preview::update(model, layout, None);

model.parent.buffer.lines.clear();
parent::update(model, layout, None);

Some(actions)
} else {
None
}
}
Message::NavigateToPath(path) => {
// TODO: check in set current to path and extend enumeration request with filename
let directory = if path.is_file() {
path.parent().unwrap()
} else {
path.as_path()
};

let mut actions = Vec::new();
if let Some(current_actions) = path::set_current_to_path(model, directory) {
actions.extend(current_actions);
}

model.current.buffer.lines.clear();
current::update(model, layout, None);

model.parent.buffer.lines.clear();
parent::update(model, layout, None);

model.preview.buffer.lines.clear();
preview::update(model, layout, None);

model.history.add(&model.current.path);

Some(actions)
}
Message::OpenCurrentSelection => {
if model.mode != Mode::Navigation {
return None;
Expand Down Expand Up @@ -338,100 +432,6 @@ pub fn update(
None
}
Message::Resize(x, y) => Some(vec![RenderAction::Pre(PreRenderAction::Resize(*x, *y))]),
Message::SelectCurrent => {
if model.mode != Mode::Navigation {
None
} else if let Some(mut actions) = path::set_current_to_selected(model) {
let current_content = model.current.buffer.lines.clone();

buffer::set_content(
&model.mode,
&mut model.current.buffer,
model.preview.buffer.lines.clone(),
);
current::update(model, layout, None);

history::set_cursor_index(
&model.current.path,
&model.history,
&mut model.current.buffer,
);

if let Some(preview_actions) = path::set_preview_to_selected(model, false, true) {
actions.extend(preview_actions);
}
model.preview.buffer.lines.clear();
preview::update(model, layout, None);

buffer::set_content(&model.mode, &mut model.parent.buffer, current_content);
parent::update(model, layout, None);

model.history.add(&model.current.path);

Some(actions)
} else {
None
}
}
Message::SelectParent => {
if model.mode != Mode::Navigation {
None
} else if let Some(mut actions) = path::set_current_to_parent(model) {
let current_content = model.current.buffer.lines.clone();

buffer::set_content(
&model.mode,
&mut model.current.buffer,
model.parent.buffer.lines.clone(),
);
current::update(model, layout, None);

history::set_cursor_index(
&model.current.path,
&model.history,
&mut model.current.buffer,
);

if let Some(preview_actions) = path::set_preview_to_selected(model, true, false) {
actions.extend(preview_actions);
}
buffer::set_content(&model.mode, &mut model.preview.buffer, current_content);
preview::update(model, layout, None);

model.parent.buffer.lines.clear();
parent::update(model, layout, None);

Some(actions)
} else {
None
}
}
Message::SelectPath(path) => {
// TODO: check in set current to path and extend enumeration request with filename
let directory = if path.is_file() {
path.parent().unwrap()
} else {
path.as_path()
};

let mut actions = Vec::new();
if let Some(current_actions) = path::set_current_to_path(model, directory) {
actions.extend(current_actions);
}

model.current.buffer.lines.clear();
current::update(model, layout, None);

model.parent.buffer.lines.clear();
parent::update(model, layout, None);

model.preview.buffer.lines.clear();
preview::update(model, layout, None);

model.history.add(&model.current.path);

Some(actions)
}
Message::Quit => Some(vec![
RenderAction::Post(PostRenderAction::Task(Task::SaveHistory(
model.history.clone(),
Expand Down
6 changes: 3 additions & 3 deletions yeet-keymap/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ impl Default for KeyMap {
Key::new(KeyCode::from_char('g'), vec![]),
Key::new(KeyCode::from_char('h'), vec![]),
],
Binding::Message(Message::SelectPath(get_home_path())),
Binding::Message(Message::NavigateToPath(get_home_path())),
),
(
vec![Key::new(KeyCode::from_char('h'), vec![])],
Binding::Message(Message::SelectParent),
Binding::Message(Message::NavigateToParent),
),
(
vec![Key::new(KeyCode::from_char('l'), vec![])],
Binding::Message(Message::SelectCurrent),
Binding::Message(Message::NavigateToCurrent),
),
(
vec![Key::new(KeyCode::from_char('m'), vec![])],
Expand Down
6 changes: 3 additions & 3 deletions yeet-keymap/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ pub enum Message {
ExecuteCommand,
ExecuteCommandString(String),
KeySequenceChanged(String),
NavigateToCurrent,
NavigateToParent,
NavigateToPath(PathBuf),
OpenCurrentSelection,
PathEnumerationContentChanged(PathBuf, Vec<(ContentKind, String)>),
PathEnumerationFinished(PathBuf),
PathRemoved(PathBuf),
PathsAdded(Vec<PathBuf>),
PreviewLoaded(PathBuf, Vec<String>),
Resize(u16, u16),
SelectCurrent,
SelectParent,
SelectPath(PathBuf),
Quit,
}

Expand Down

0 comments on commit 00768ec

Please sign in to comment.