Skip to content

Commit

Permalink
Added missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Jun 24, 2024
1 parent fc6b3a1 commit 76aece4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/command_info.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import std/[options, tables]
import events, input_api

type
CommandKeyInfo* = object
keys*: string
command*: string
context*: string

CommandInfos* = ref object
built: bool = false
commandToKeys*: Table[string, seq[CommandKeyInfo]]

proc invalidate*(self: CommandInfos) =
self.built = false
self.commandToKeys.clear()

proc rebuild*(self: CommandInfos, eventHandlerConfigs {.byref.}: Table[string, EventHandlerConfig]) =
if self.built:
return

self.built = true
self.commandToKeys.clear()
for (context, c) in eventHandlerConfigs.pairs:
if not c.commands.contains(""):
continue
for (keys, command) in c.commands[""].pairs:
let (action, args) = command.parseAction
self.commandToKeys.mgetOrPut(action, @[]).add(CommandKeyInfo(
keys: keys,
command: command,
context: context,
))

proc getInfos*(self: CommandInfos, command: string): Option[seq[CommandKeyInfo]] =
if self.commandToKeys.contains(command):
return self.commandToKeys[command].some

proc wasBuilt*(self: CommandInfos): bool = self.built

0 comments on commit 76aece4

Please sign in to comment.