Skip to content

fidgetingbits/talon-python-command-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

This is a python implementation of the file-based RPC command server for use with Talon clients. This is mostly just a port of the original Typescript implementation by Pokey here.

The implementation is fairly generic, the ideas that any application plugin written in python could import this class, and relatively seamlessly talk with a command client on the talon side. The command client on the talon side is currently a working process here, but this server has been tested with it to make sure it works fine.

Usage

A simple example of how a python plugin can use the server:

from .talon_command_server import TalonCommandServer

class ExampleCommandServer:
    COMMUNICATION_DIRECTORY = "/tmp/example-talon"

    def __init__(self, command_handler):
        self.command_handler = command_handler

    def start_server(self):
        server = TalonCommandServer(self.COMMUNICATION_DIRECTORY)
        if not server.init_ok:
            print("ERROR: Unable to initialize command server. Exiting early.")
            return
        server.command_loop(self.command_handler)

def command_handler(command, *args):
    """Main handler of all commands coming from Talon"""
    print(f"example command handler: {command} {args}")
    return "example command response"

# Plugin entry point
def main():
    server = command_server.ExampleCommandServer(command_handler)
    t = threading.Thread(target=server.start_server)
    t.daemon = True
    t.start()

if __name__ == "__main__":
    main()

Installation

At the moment talon_command_server.py is just meant to be copied to the plugin source directory that you're developing from, but in the future maybe we can standardize on something like $HOME/.talon/lib/python/ for installing helper stuff like this.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages