Skip to content

Commit

Permalink
Take snapshots of hat map
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Nov 7, 2021
1 parent 81b87ac commit 635347a
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion src/marks/mark.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -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)

0 comments on commit 635347a

Please sign in to comment.