Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design question: why separating write_current_state and all the other save_state #85

Open
ChrisGVE opened this issue Jan 6, 2025 · 1 comment
Labels
question Further information is requested

Comments

@ChrisGVE
Copy link

ChrisGVE commented Jan 6, 2025

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.

@MLFlexer
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants