Skip to content

Commit

Permalink
Update to modalkit{,-ratatui}@0.0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssa committed Aug 12, 2024
1 parent 04480ed commit f2d7156
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ edit = "0.1.4"
humansize = "2.0.0"

[dependencies.modalkit]
version = "0.0.19"
version = "0.0.20"
#git = "https://github.com/ulyssa/modalkit"
#rev = "cb8c8aeb9a499b9b16615ce144f9014d78036e01"
#rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272"

[dependencies.modalkit-ratatui]
version = "0.0.19"
version = "0.0.20"
#git = "https://github.com/ulyssa/modalkit"
#rev = "cb8c8aeb9a499b9b16615ce144f9014d78036e01"
#rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272"

[dependencies.matrix-sdk]
version = "0.7.1"
Expand Down
33 changes: 23 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ use modalkit::{

use modalkit_ratatui::{
cmdbar::CommandBarState,
screen::{Screen, ScreenState, TabLayoutDescription},
windows::WindowLayoutDescription,
screen::{Screen, ScreenState, TabbedLayoutDescription},
windows::{WindowLayoutDescription, WindowLayoutState},
TerminalCursor,
TerminalExtOps,
Window,
Expand Down Expand Up @@ -176,6 +176,17 @@ fn config_tab_to_desc(
Ok(desc)
}

fn restore_layout(
area: Rect,
settings: &ApplicationSettings,
store: &mut ProgramStore,
) -> IambResult<FocusList<WindowLayoutState<IambWindow, IambInfo>>> {
let layout = std::fs::read(&settings.layout_json)?;
let tabs: TabbedLayoutDescription<IambInfo> =
serde_json::from_slice(&layout).map_err(IambError::from)?;
tabs.to_layout(area.into(), store)
}

fn setup_screen(
settings: ApplicationSettings,
store: &mut ProgramStore,
Expand All @@ -186,12 +197,14 @@ fn setup_screen(

match settings.layout {
config::Layout::Restore => {
if let Ok(layout) = std::fs::read(&settings.layout_json) {
let tabs: TabLayoutDescription<IambInfo> =
serde_json::from_slice(&layout).map_err(IambError::from)?;
let tabs = tabs.to_layout(area.into(), store)?;

return Ok(ScreenState::from_list(tabs, cmd));
match restore_layout(area, &settings, store) {
Ok(tabs) => {
return Ok(ScreenState::from_list(tabs, cmd));
},
Err(e) => {
// Log the issue with restoring and then continue.
tracing::warn!(err = %e, "Failed to restore layout from disk");
},
}
},
config::Layout::New => {},
Expand Down Expand Up @@ -242,7 +255,7 @@ struct Application {
focused: bool,

/// The tab layout before the last executed [TabAction].
last_layout: Option<TabLayoutDescription<IambInfo>>,
last_layout: Option<TabbedLayoutDescription<IambInfo>>,

/// Whether we need to do a full redraw (e.g., after running a subprocess).
dirty: bool,
Expand Down Expand Up @@ -479,7 +492,7 @@ impl Application {
None
},
Action::Command(act) => {
let acts = store.application.cmds.command(&act, &ctx)?;
let acts = store.application.cmds.command(&act, &ctx, &mut store.registers)?;
self.action_prepend(acts);

None
Expand Down
6 changes: 2 additions & 4 deletions src/windows/room/scrollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
let dir = ctx.get_search_regex_dir();
let dir = flip.resolve(&dir);

let lsearch = store.registers.get(&Register::LastSearch)?;
let lsearch = lsearch.value.to_string();
let lsearch = store.registers.get_last_search().to_string();
let needle = Regex::new(lsearch.as_ref())?;

let (mc, needs_load) = self.find_message(key, dir, &needle, count, info);
Expand Down Expand Up @@ -753,8 +752,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
let dir = ctx.get_search_regex_dir();
let dir = flip.resolve(&dir);

let lsearch = store.registers.get(&Register::LastSearch)?;
let lsearch = lsearch.value.to_string();
let lsearch = store.registers.get_last_search().to_string();
let needle = Regex::new(lsearch.as_ref())?;

let (mc, needs_load) = self.find_message(key, dir, &needle, count, info);
Expand Down

0 comments on commit f2d7156

Please sign in to comment.