Skip to content

Latest commit

 

History

History
119 lines (95 loc) · 3.22 KB

README.md

File metadata and controls

119 lines (95 loc) · 3.22 KB

nim-wox

Test nim-wox

Helper library for writing Wox plugins in Nim

demo

Contents

Installation

nimble install wox

Usage

import browsers, json
import wox

proc query(wp: Wox, params: varargs[string]) =
  # create a global Wox object
  # add an item to Wox
  wp.add("Github", # title
         "How people build software", # subtitle
         "Images\\gh.png", # icon
         "", # context data, leave blank if you don't need context menu
         "openUrl", # method
         "https://github.com/", # method params
         false # don't hide
  )
  # 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("http://roose.github.io/nim-wox/wox.html")
  # register `query` and `openUrl` for call from Wox
  wp.register("query", query)
  wp.register("openUrl", openUrl)
  # run called proc
  wp.run()

Context menu example:

import browsers, json
import wox

proc query(wp: Wox, params: varargs[string]) =
  # create a global Wox object
  # add an item to Wox
  wp.add("postcss", # title
         "Tool for transforming style", # subtitle
         "Images\\postcss.png", # icon
         "https://www.npmjs.com/package/postcss", # context data
         "openUrl", # method
         "https://github.com/postcss/postcss", # method params
         false # don't hide
  )
  # send output to Wox
  echo wp.results()

proc contextmenu(wp: Wox, params: varargs[string]) =
  # proc for context menu action
  wp.add("Open npm page", # title
         "", # subtitle, leave blank
         "Images\\npm.png", # icon
         "", # context data, leave blank
         "openUrl", # method
         params[0], # method params, given context data from query method
         false # don't hide
  )
  # send output to Wox
  echo wp.results()

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

when isMainModule:
  # url for help magic action
  var wp = newWox("http://roose.github.io/nim-wox/wox.html")
  # register `query` and `openUrl` for call from Wox
  wp.register("query", query)
  wp.register("openUrl", openUrl)
  # register `contextmenu` for call from Wox context menu by pressing Shift+Enter
  wp.register("contextmenu", contextmenu)
  # run called proc
  wp.run()

Attention: newWox is generating info.png and delete.png in the Images folder(if they don't exist). Attention #2: Wox now wrong show icons in context menu, issue

Documentation

Documentation

Tests

nimble tests

Licensing

The code and documentation are released under the MIT Licence. See the bundled LICENSE file for details.