3 ... ... .... ... ... ... ... .... ||
4 ||' || '|. | || || | '' .|| ||
5 || | '|.| ||| ||| .|' || ||
6 ||...' '| | | '|..'|' .||.
9 Created by Dylan Araps.
18 from .settings import __version__, CACHE_DIR, CONF_DIR
23 from . import sequences
26 from . import wallpaper
30 """Get the script arguments."""
31 description = "wal - Generate colorschemes on the fly"
32 arg = argparse.ArgumentParser(description=description)
34 arg.add_argument("-a", metavar="\"alpha\"",
35 help="Set terminal background transparency. \
36 *Only works in URxvt*")
38 arg.add_argument("-b", metavar="background",
39 help="Custom background color to use.")
41 arg.add_argument("--backend", metavar="backend",
42 help="Which color backend to use. \
43 Use 'wal --backend' to list backends.",
44 const="list_backends", type=str, nargs="?")
46 arg.add_argument("--theme", "-f", metavar="/path/to/file or theme_name",
47 help="Which colorscheme file to use. \
48 Use 'wal --theme' to list builtin themes.",
49 const="list_themes", nargs="?")
51 arg.add_argument("--iterative", action="store_true",
52 help="When pywal is given a directory as input and this "
53 "flag is used: Go through the images in order "
54 "instead of shuffled.")
56 arg.add_argument("--saturate", metavar="0.0-1.0",
57 help="Set the color saturation.")
59 arg.add_argument("--preview", action="store_true",
60 help="Print the current color palette.")
62 arg.add_argument("--vte", action="store_true",
63 help="Fix text-artifacts printed in VTE terminals.")
65 arg.add_argument("-c", action="store_true",
66 help="Delete all cached colorschemes.")
68 arg.add_argument("-i", metavar="\"/path/to/img.jpg\"",
69 help="Which image or directory to use.")
71 arg.add_argument("-l", action="store_true",
72 help="Generate a light colorscheme.")
74 arg.add_argument("-n", action="store_true",
75 help="Skip setting the wallpaper.")
77 arg.add_argument("-o", metavar="\"script_name\"", action="append",
78 help="External script to run after \"wal\".")
80 arg.add_argument("-q", action="store_true",
81 help="Quiet mode, don\'t print anything.")
83 arg.add_argument("-r", action="store_true",
84 help="'wal -r' is deprecated: Use \
85 (cat ~/.cache/wal/sequences &) instead.")
87 arg.add_argument("-R", action="store_true",
88 help="Restore previous colorscheme.")
90 arg.add_argument("-s", action="store_true",
91 help="Skip changing colors in terminals.")
93 arg.add_argument("-t", action="store_true",
94 help="Skip changing colors in tty.")
96 arg.add_argument("-v", action="store_true",
97 help="Print \"wal\" version.")
99 arg.add_argument("-e", action="store_true",
100 help="Skip reloading gtk/xrdb/i3/sway/polybar")
105 def parse_args_exit(parser):
106 """Process args that exit."""
107 args = parser.parse_args()
109 if len(sys.argv) <= 1:
114 parser.exit(0, "wal %s\n" % __version__)
117 print("Current colorscheme:", sep='')
121 if args.i and args.theme:
122 parser.error("Conflicting arguments -i and -f.")
129 scheme_dir = os.path.join(CACHE_DIR, "schemes")
130 shutil.rmtree(scheme_dir, ignore_errors=True)
137 parser.error("No input specified.\n"
138 "--backend, --theme, -i or -R are required.")
140 if args.theme == "list_themes":
144 if args.backend == "list_backends":
145 print("\n - ".join(["\033[1;32mBackends\033[0m:",
146 *colors.list_backends()]))
150 def parse_args(parser):
152 args = parser.parse_args()
155 logging.getLogger().disabled = True
156 sys.stdout = sys.stderr = open(os.devnull, "w")
159 util.Color.alpha_num = args.a
162 image_file = image.get(args.i, iterative=args.iterative)
163 colors_plain = colors.get(image_file, args.l, args.backend,
167 colors_plain = theme.file(args.theme, args.l)
170 colors_plain = theme.file(os.path.join(CACHE_DIR, "colors.json"))
173 args.b = "#%s" % (args.b.strip("#"))
174 colors_plain["special"]["background"] = args.b
175 colors_plain["colors"]["color0"] = args.b
178 wallpaper.change(colors_plain["wallpaper"])
180 sequences.send(colors_plain, to_send=not args.s, vte_fix=args.vte)
182 if sys.stdout.isatty():
185 export.every(colors_plain)
188 reload.env(tty_reload=not args.t)
199 """Main script function."""
200 util.create_dir(os.path.join(CONF_DIR, "templates"))
201 util.create_dir(os.path.join(CONF_DIR, "colorschemes/light/"))
202 util.create_dir(os.path.join(CONF_DIR, "colorschemes/dark/"))
207 parse_args_exit(parser)
211 if __name__ == "__main__":