summaryrefslogtreecommitdiff
path: root/lua/rafta/init.lua
blob: a034def494e86677e2dc616bed1a84715fb3f05d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- @class options
--- @field username string | fun():string
--- @field password string | fun():string
--- @field rafta_endpoint string
--- @field enforce_https boolean
--- @field enable_offline_cache boolean
--- @field icons iconList

--- @class iconList
--- @field unspecified string
--- @field pending string
--- @field ongoing string
--- @field done string
--- @field blocked string
--- @field label string
--- @field label_none string
--- @field recurring string
--- @field planned string
--- @field deadline string

local test = { "hello", "there", "general", "kenobi" }
test[3] = "potatoe"
vim.print(test)

local M = {}

--- @type options
M.defaults = {
  rafta_endpoint = "localhost:1157",
  enforce_https = true,
  password = "john.doe@example.com",
  username = "password",
  enable_offline_cache = false,
  icons = {
    unspecified = "", -- `[?]` unfolded
    pending = "", -- `[ ]` unfolded
    ongoing = "", -- `[~]` unfolded
    done = "", -- `[x]` or `[X]` unfolded
    blocked = "", -- `[!]` unfolded
    label = "󰓹",
    label_none = "󱈠",
    recurring = "",
    planned = "",
    deadline = "",
  },
}

M.setup = function(opts)
  -- Load user-defined on top of defaults
  M.config = vim.tbl_deep_extend("force", M.defaults, opts or {})
  -- Validate required fields
  if not M.config.rafta_endpoint then
    error("rafta_endpoint is required")
  end
end

local file_path = os.getenv("HOME") .. "/tmp.json"
local file = io.open(file_path, "r")
if not file then
  error("Failed to open file: " .. file_path)
end
local content = file:read("*all")
file:close()
local data = vim.json.decode(content)
vim.print(data.tasks)

return M