From 635347a391322c0a1e9c44d52f1775b24d1aaa0f Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Sun, 7 Nov 2021 17:25:24 +0000 Subject: [PATCH] Take snapshots of hat map --- src/marks/mark.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/marks/mark.py b/src/marks/mark.py index 30e8f933..33826973 100644 --- a/src/marks/mark.py +++ b/src/marks/mark.py @@ -1,11 +1,16 @@ from dataclasses import dataclass +import uuid from pathlib import Path from ..conventions import get_cursorless_list_name -from talon import Module, actions, app, Context, fs, cron +from talon import Module, actions, app, Context, fs, cron, speech_system from ..csv_overrides import init_csv_and_watch_changes mod = Module() ctx = Context() +cursorless_ctx = Context() +cursorless_ctx.matches = r""" +app: vscode +""" mod.list("cursorless_hat_color", desc="Supported hat colors for cursorless") @@ -50,6 +55,7 @@ def cursorless_decorated_symbol(m) -> str: "type": "decoratedSymbol", "symbolColor": hat_style_name, "character": m.any_alphanumeric_key, + "snapshotId": get_snapshot_id(), } } @@ -188,3 +194,51 @@ def on_watch(path, flags): app.register("ready", on_ready) + + +@mod.action_class +class Actions: + def cursorless_take_snapshot(): + """Take snapshot of hats""" + pass + + +@cursorless_ctx.action_class("user") +class CursorlessActions: + def cursorless_take_snapshot(): + actions.user.vscode_with_plugin_and_wait( + "cursorless.takeHatMapSnapshot", + get_snapshot_id(), + ) + + +@ctx.action_class("user") +class GlobalActions: + def cursorless_take_snapshot(): + pass + + +snapshot_id = None + + +def get_snapshot_id(): + global snapshot_id + + if snapshot_id is None: + snapshot_id = uuid.uuid4().hex + + return snapshot_id + + +def clear_snapshot_id(): + global snapshot_id + + snapshot_id = None + + +def pre_phrase(_): + actions.user.cursorless_take_snapshot() + + +speech_system.register("pre:phrase", pre_phrase) +speech_system.register("post:phrase", clear_snapshot_id)