8000 feature: escape action by fabienjuif · Pull Request #174 · gabm/Satty · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feature: escape action #174

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

Merged
merged 1 commit into from
May 8, 2025
Merged

Conversation

fabienjuif
Copy link
Collaborator
@fabienjuif fabienjuif commented May 8, 2025

fixes #172

How

I've reused the action on enter idea.
I've made 3 new actions but we could argue that early_exit is enough.

Example

➜  void-packages git:(satty) ✗ grim -t png -g "$(slurp -d)" - | satty -f - --action-on-escape=save-to-clipboard-and-exit --copy-command=wl-copy
config file not found
Copied to clipboard.
➜  void-packages git:(satty) ✗ 

image

Misc

My first attempt was roughly this but it was unconsistent:

    // /!\ not consistent
    pub fn request_render_then(&self, action: Action, callback: impl FnOnce() + 'static) {
        let handler_id_rc: Rc<RefCell<Option<glib::SignalHandlerId>>> = Rc::new(RefCell::new(None));
        let callback_rc: CallbackBox = Rc::new(RefCell::new(Some(Box::new(callback))));
    
        let obj = self.obj();
        let handler_id_clone = handler_id_rc.clone();
    
        let handler_id = obj.connect_render(move |gl_area, _| {
            // call the callback
            if let Some(callback) = callback_rc.borrow_mut().take() {
                callback();
            }
            // disconnect handler
            if let Some(id) = handler_id_clone.borrow_mut().take() {
                gl_area.disconnect(id);
            }
            glib::Propagation::Proceed
        });
    
        handler_id_rc.borrow_mut().replace(handler_id);
        self.request_render.borrow_mut().replace(action);
        obj.queue_render();
    }

@RobertMueller2
Copy link
Collaborator

Thanks for the PR. I'll review this in a bit. Sorry for the additional trouble, but would you mind using the "self review" commit as a fixup commit for the first, and openening a separate PR for the fix for #170?

@fabienjuif
Copy link
Collaborator Author

I am doing it.

I am curious, why do not you use "squash merge"?

@RobertMueller2
Copy link
Collaborator

I am doing it.

I am curious, why do not you use "squash merge"?

Well, it's a valid question. I suppose in such an easy and obvious case we could. But generally spoken, the author may have had reasons to create separate commits which should also be visible in commit history after merging. For bigger PRs it could become difficult to distinguish this from mere formatting changes. So with that in mind, personally, I'd rather prefer squashing that in the PR. But it's no more than a personal feeling. I don't know how @gabm feels about this. ;)

Copy link
Collaborator
@RobertMueller2 RobertMueller2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could do with another cargo fmt, right? Other than that and the change below, looks good to me.

@fabienjuif
Copy link
Collaborator Author

image

grim -t png -g "$(slurp -d)" - | cargo run -- -f - --action-on-escape save-to-clipboard-and-exit --copy-command=wl-copy

@fabienjuif
Copy link
Collaborator Author

Should be fine @RobertMueller2 thank you for the review!

@RobertMueller2
Copy link
Collaborator

github doesn't let me right now, I'll try again later.

@RobertMueller2 RobertMueller2 merged commit 10b58bb into gabm:main May 8, 2025
3 checks passed
@fabienjuif fabienjuif deleted the escape_action branch May 8, 2025 15:51
@RobertMueller2 RobertMueller2 mentioned this pull request May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request / --action-on-{exit,escape}
2 participants
0