resurrect.wezterm icon indicating copy to clipboard operation
resurrect.wezterm copied to clipboard

Design question: why separating `write_current_state` and all the other `save_state`

Open ChrisGVE opened this issue 11 months ago • 1 comments

It is great to have a restore session upon loading (though I am still trying to make it work 🤣 but that's on me...).

I have a question though: why decoupling the write_current_state from the other save_state function? i.e., I could expect that the periodic save would take care of the write_current_state because that's the closest thing to complement a restore upon restart. Also, I'm not super clear why the write_current_state requires a type parameter when the documentation indicates that it expects a workspace?

Going a bit deeper, it is clear that the example give to act on event would require to add

-- Write the current state when it has been selected
wezterm.on("smart_workspace_switcher.workspace_switcher.chosen", function(window, workspace, label)
	resurrect.write_current_state(label, "workspace")
end)

to complement the

-- Saves the state whenever I select a workspace
wezterm.on("smart_workspace_switcher.workspace_switcher.selected", function(window, path, label)
	local workspace_state = resurrect.workspace_state
	resurrect.save_state(workspace_state.get_workspace_state())
end)

As well when creating a new workspace, it should be modified with

-- Load the state whenever I create a new workspace
wezterm.on("smart_workspace_switcher.workspace_switcher.created", function(window, path, label)
	local workspace_state = resurrect.workspace_state

	workspace_state.restore_workspace(resurrect.load_state(label, "workspace"), {
		window = window,
		relative = true,
		restore_text = true,
		on_pane_restore = resurrect.tab_state.default_on_pane_restore,
	})
	resurrect.write_current_state(label, "workspace")
end)

Do let me know if I'm wrong please, it'll help me getting my understanding right.

ChrisGVE avatar Jan 06 '25 08:01 ChrisGVE

It is great to have a restore session upon loading (though I am still trying to make it work 🤣 but that's on me...).

I have a question though: why decoupling the write_current_state from the other save_state function? i.e., I could expect that the periodic save would take care of the write_current_state because that's the closest thing to complement a restore upon restart.

This is because if i switch workspaces, then i would like to have the new workspace be saved as the current workspace, but I don't want to save it as there should be no changes to it at the moment i switch to it.

Also, I'm not super clear why the write_current_state requires a type parameter when the documentation indicates that it expects a workspace?

This is for future proofing, as the different states that can be saved are workspace, window and tab. I will add an issue, to support these other states.

Going a bit deeper, it is clear that the example give to act on event would require to add

-- Write the current state when it has been selected wezterm.on("smart_workspace_switcher.workspace_switcher.chosen", function(window, workspace, label) resurrect.write_current_state(label, "workspace") end)

to complement the

-- Saves the state whenever I select a workspace wezterm.on("smart_workspace_switcher.workspace_switcher.selected", function(window, path, label) local workspace_state = resurrect.workspace_state resurrect.save_state(workspace_state.get_workspace_state()) end)

As well when creating a new workspace, it should be modified with

-- Load the state whenever I create a new workspace wezterm.on("smart_workspace_switcher.workspace_switcher.created", function(window, path, label) local workspace_state = resurrect.workspace_state

workspace_state.restore_workspace(resurrect.load_state(label, "workspace"), { window = window, relative = true, restore_text = true, on_pane_restore = resurrect.tab_state.default_on_pane_restore, }) resurrect.write_current_state(label, "workspace") end)

Do let me know if I'm wrong please, it'll help me getting my understanding right.

The smart_workspace_switcher.workspace_switcher.selected event is a "catch-all" event which is triggered, whenever you select an element from the picker, thus should be able to just add it to that event, like I did here

MLFlexer avatar Jan 23 '25 09:01 MLFlexer