Giter Club home page Giter Club logo

Comments (3)

kovidgoyal avatar kovidgoyal commented on August 27, 2024

You cannot intercept signals sent to other processes. What is your
actual use case.

from kitty.

Raghav-rv28 avatar Raghav-rv28 commented on August 27, 2024

I am doing this to build a tui which helps manages session and easily configure the terminal:

i would like to build a script which saves the session data for a particular kitty terminal instance. we have inbuilt commands like kitty @ ls which help us do this. i built a python kitten script which looks something like this:

from typing import List
import json
import os
from kitty.boss import Boss

def main(args: List[str]) -> str:
    pass

from kittens.tui.handler import result_handler
@result_handler(no_ui=True)
def handle_result(args: List[str], answer: str, target_window_id: int, boss: Boss) -> None:
    w = boss.window_id_map.get(target_window_id)
    if w is not None:
        json_data_str = boss.call_remote_control(w, ('ls', f'--match=id:{w.id}'))
        json_data = json.loads(json_data_str)
        # Define the file path
        home_dir = os.path.expanduser("~")
        
        # Define the file path with the correct username
        file_path = os.path.join(home_dir, '.config','kitty', 'lastsession.kitty')        
        # Check if the file exists
        if not os.path.exists(file_path):
            # If the file doesn't exist, create a new one
            with open(file_path, 'w') as f:
                json.dump({}, f)  # Write an empty JSON object
        
        # Write JSON data to the file
        with open(file_path, 'w') as f:
            json.dump(json_data, f)
    boss.close_tab()

this is the simplified version but i have more ifs and else which check for different arguments incoming. i have also mapped some shortcuts in my kitty config file as follows:

map ctrl+shift+q kitten autosave.py close_tab
map ctrl+shift+w kitten autosave.py close_window

i tried the same for alt+f4 which is a common way of closing the terminal, but no dice. Then as i researched more i found that if i am 'trapping' the SIGTERM signal for the kitty instance it would cover the whole "accidentally closing terminal edge case" instead of me handling each individual closing separately.

Any help would be useful.

from kitty.

kovidgoyal avatar kovidgoyal commented on August 27, 2024

If you want to perform special actions on window close events, you use
the watcher infrastructure in kitty
https://sw.kovidgoyal.net/kitty/conf/#opt-kitty.watcher

You absolutely cannot handle signals in your code. signals are an
asynchronous, global mechanism.

from kitty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.