-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgmanager.nim
81 lines (67 loc) · 2.23 KB
/
bgmanager.nim
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#[
-----------------------------------------------------
Background Manager V4 (Designed for Arch Linux)
For i3 (might work with other stuff)
By Lamar "Tony" Daughma
-----------------------------------------------------
]#
import
osproc, os, sequtils, strutils, random, parseopt, streams
include
displayImg, config
#Sets ~/wallpaper folder as default target
let
source = getHomeDir() / "Wallpapers"
wallpapers: seq[filePath] = toSeq(walkDir(source))
discard existsOrCreateDir(source)
var
parse = initOptParser("") # Gets commandline arguments(--long -s)
time = 1 # Default time to switch between wallpapers
# Placeholder help
proc help():void =
echo("bannannanna batman :P \nWorking Help Diag Incoming")
proc runManager(conf: Config):void =
case conf.mode:
of single:
singleImg(conf.singleImage, wallpapers)
of randSelect:
discard existsOrCreateDir(conf.folderPath)
randomImg(conf.imgTimer, toSeq(walkdir(conf.folderPath)))
of ordered:
echo "not implimented yet. exiting."
# Argument management:
# Parses all command-line arguments
for kind, key, val in parse.getopt():
# Manages the kind of arguments it can handle.
case kind
# Your normal --long -s <short> args
of cmdLongOption, cmdShortOption:
# Does different things dependind on value of `key`
case key
# Time argument
of "time", "t":
time = parseInt(val)
# Help dialogue, I'll have to learn how to make one now -_-
of "help", "h":
help()
# Single image tool (for those that just want one image, idk why you need this but its here)
of "single", "s":
singleImg(val, wallpapers)
# Random image tool
of "random", "r":
randomImg(if val == "": time else: parseInt(val), wallpapers)
# Lists all images that it can display
of "list", "l":
listSrc(wallpapers)
#runs initialise system
of "init", "initialise", "i":
discard existsOrCreateDir(source)
#runs the config creation
of "config","c":
createConfig()
#If no option supplied
of "normal", "n", "":
var conf = readConfig(source)
runManager(conf)
# We don't need cmdArgument and cmdEnd indicates that end of command line reached/
of cmdArgument, cmdEnd: assert(false)