wox

The MIT License (MIT) https://opensource.org/licenses/MIT

Copyright (c) 2016 roose

This module implements helper procs for creating Wox plugins. Example:

import browsers
import wox

proc query(wp: Wox, params: varargs[string]) =
  # create a global Wox object
  # add an item to Wox
  wp.add("Github", "How people build software", "Images\\gh.png",
          "openUrl", "https://github.com/", false)
  # send output to Wox
  echo wp.results()

proc openUrl(wp: Wox, params: varargs[string]) =
  # open url in default browser
  openDefaultBrowser(params[0])

when isMainModule:
  var wp = newWox()
  # register `query` and `openUrl` for call from Wox
  wp.register("query", query)
  wp.register("openUrl", openUrl)
  # run called proc
  wp.run()

.

Warning: settings is JsonNode, on assign new setting value be careful, convert it to JsonNode, Example:

wp.settings["login"] = "john" # Error, because is string
wp.settings["login"] = newJString("john") # Right

Types

PluginInfo = object
  id*: string
  name*: string
  keyword*: seq[string]
  desc*: string
  author*: string
  version*: string
  site*: string
  icon*: string
  file*: string
Item = object
  Title*: string
  SubTitle*: string
  IcoPath*: string
  JsonRPCAction*: Action
Wox item object
Wox = ref object
  data*: Result
  pluginDir*: string
  plugin*: PluginInfo
  settingsDir*: string
  cacheDir*: string
  settings*: JsonNode
Wox object
RpcProc = proc (self: Wox; params: varargs[string])
SortBy = enum
  byTitle, bySub, byTitleSub
Sort by title or subtitle or title and subtitle

Procs

proc register(self: Wox; name: string; prc: RpcProc) {...}{.raises: [Exception],
    tags: [RootEffect].}
Register proc as name
proc query(wp: Wox, params: varargs[string]) =
  # code
wp.register("query", query)
proc call(self: Wox; name: string; params: varargs[string]) {...}{.
    raises: [Exception, KeyError], tags: [RootEffect].}
Call proc by it's name
proc run(self: Wox; default = "") {...}{.raises: [Defect, IOError, OSError, ValueError,
                                      JsonParsingError, Exception, KeyError],
                              tags: [ReadIOEffect, WriteIOEffect, RootEffect].}
Parse JsonRPC from Wox and call method with params
wp.run()
proc isCacheOld(name: string; maxAge: float = 0): bool {...}{.raises: [KeyError, IOError,
    Defect, OSError, ValueError, JsonParsingError, Exception], tags: [ReadIOEffect,
    WriteIOEffect, ReadEnvEffect, WriteDirEffect, ReadDirEffect, TimeEffect].}
Сhecks the cache has expired or not
if isCacheOld("cache_file", 60):
  # code
proc newWox(): Wox {...}{.raises: [IOError, Defect, OSError, ValueError, JsonParsingError,
                          Exception, KeyError], tags: [ReadIOEffect, WriteIOEffect,
    ReadEnvEffect, WriteDirEffect, ReadDirEffect].}
Create a Wox object
var wp = newWox()

Methods

method add(self: Wox; title, sub = ""; icon = ""; `method` = ""; params = ""; hide: bool = true) {...}{.
    base, raises: [], tags: [].}
Add item to the return list
wp.add("Github", "How people build software", "Images\\gh.png",
       "openUrl", "https://github.com/", false)
method insert(self: Wox; title, sub = ""; icon = ""; `method` = ""; params = "";
             hide: bool = true; pos: int = 0) {...}{.base, raises: [], tags: [].}
Insert item at pos to the return list
wp.insert("Github", "How people build software", "Images\\gh.png",
          "openUrl", "https://github.com/", false, 0)
method results(self: Wox): string {...}{.base, raises: [Defect, IOError, OSError, IndexError,
    ValueError], tags: [WriteIOEffect].}
Return all results
wp.results()
method saveSettings(self: Wox) {...}{.base, raises: [KeyError, IOError, Defect, OSError,
    ValueError, JsonParsingError, Exception], tags: [ReadIOEffect, WriteIOEffect,
    ReadEnvEffect, WriteDirEffect, ReadDirEffect].}
Save settings to settings.json
wp.saveSettings()
method loadCache(self: Wox; name: string): JsonNode {...}{.base, raises: [KeyError, IOError,
    Defect, OSError, ValueError, JsonParsingError, Exception], tags: [ReadIOEffect,
    WriteIOEffect, ReadEnvEffect, WriteDirEffect, ReadDirEffect].}
Load cached data from file
wp.loadCache("cache_file")
method saveCache(self: Wox; name: string; data: JsonNode) {...}{.base, raises: [KeyError,
    IOError, Defect, OSError, ValueError, JsonParsingError, Exception], tags: [
    ReadIOEffect, WriteIOEffect, ReadEnvEffect, WriteDirEffect, ReadDirEffect].}
Save cache to file
wp.saveCache("cache_file")
method sort(self: Wox; query: string; sortBy = byTitleSub; minScore: float = 0.0;
           maxResults = 0) {...}{.base, raises: [ValueError, EInvalidPeg, Exception],
                          tags: [RootEffect].}
Fuzzy sorting the results, default sorted by title and subtitle
wp.sort(query, minScore = 10, maxResults = 10, sortBy = byTitle)