This commit is contained in:
2025-02-06 06:26:44 +03:00
parent 5bbb99c3f9
commit 5ad2062e5c
55 changed files with 516 additions and 590 deletions

View File

@@ -109,11 +109,11 @@ pub fn profile_path_source() !string {
}
pp := profile_path()!
if os.exists(pp) {
res := os.execute("source ${pp}")
res := os.execute('source ${pp}')
if res.exit_code != 0 {
console.print_stderr("WARNING: your profile is corrupt: ${pp}")
return error("profile corrupt")
}else{
console.print_stderr('WARNING: your profile is corrupt: ${pp}')
return error('profile corrupt')
} else {
return 'source ${pp}'
}
}
@@ -122,10 +122,8 @@ pub fn profile_path_source() !string {
// return source $path && .
// or empty if it doesn't exist
pub fn profile_path_source_and() !string {
p:=profile_path_source() or {
return ""
}
pub fn profile_path_source_and() !string {
p := profile_path_source() or { return '' }
return '${p} && '
}

View File

@@ -26,10 +26,10 @@ pub mut:
pub fn download(args_ DownloadArgs) !pathlib.Path {
mut args := args_
args.dest = args.dest.trim(" ").trim_right("/")
args.expand_dir = args.expand_dir.trim(" ").trim_right("/")
args.expand_file = args.expand_file.replace("//","/")
args.dest = args.dest.replace("//","/")
args.dest = args.dest.trim(' ').trim_right('/')
args.expand_dir = args.expand_dir.trim(' ').trim_right('/')
args.expand_file = args.expand_file.replace('//', '/')
args.dest = args.dest.replace('//', '/')
console.print_header('download: ${args.url}')
if args.name == '' {
@@ -77,23 +77,23 @@ pub fn download(args_ DownloadArgs) !pathlib.Path {
// Clean up all related files when resetting
if os.exists(args.dest) {
if os.is_dir(args.dest) {
os.rmdir_all(args.dest) or { }
os.rmdir_all(args.dest) or {}
} else {
os.rm(args.dest) or { }
os.rm(args.dest) or {}
}
}
if os.exists(args.dest + '_') {
if os.is_dir(args.dest + '_') {
os.rmdir_all(args.dest + '_') or { }
os.rmdir_all(args.dest + '_') or {}
} else {
os.rm(args.dest + '_') or { }
os.rm(args.dest + '_') or {}
}
}
if os.exists(args.dest + '.meta') {
if os.is_dir(args.dest + '.meta') {
os.rmdir_all(args.dest + '.meta') or { }
os.rmdir_all(args.dest + '.meta') or {}
} else {
os.rm(args.dest + '.meta') or { }
os.rm(args.dest + '.meta') or {}
}
}
// Recreate meta file after cleanup
@@ -119,9 +119,9 @@ pub fn download(args_ DownloadArgs) !pathlib.Path {
// Clean up any existing temporary file/directory before download
if os.exists(dest0.path) {
if os.is_dir(dest0.path) {
os.rmdir_all(dest0.path) or { }
os.rmdir_all(dest0.path) or {}
} else {
os.rm(dest0.path) or { }
os.rm(dest0.path) or {}
}
}
cmd := '

View File

@@ -12,7 +12,7 @@ pub enum NotifyEvent {
}
// NotifyCallback is the function signature for event callbacks
pub type NotifyCallback = fn (event NotifyEvent, path string , args map[string]string)
pub type NotifyCallback = fn (event NotifyEvent, path string, args map[string]string)
// WatchEntry represents a watched path and its associated callback
struct WatchEntry {
@@ -28,7 +28,7 @@ pub mut:
name string
watch_list []WatchEntry
is_watching bool
args map[string]string
args map[string]string
}
// new creates a new Notifier instance
@@ -39,8 +39,8 @@ pub fn new(name string) !&Notifier {
}
return &Notifier{
name: name
watch_list: []WatchEntry{}
name: name
watch_list: []WatchEntry{}
is_watching: false
}
}
@@ -52,9 +52,9 @@ pub fn (mut n Notifier) add_watch(path string, callback NotifyCallback) ! {
}
n.watch_list << WatchEntry{
path: path
path: path
callback: callback
pid: 0
pid: 0
}
println('Added watch for: ${path}')
@@ -86,13 +86,13 @@ pub fn (mut n Notifier) start() ! {
n.is_watching = true
if n.watch_list.len>1{
return error("only support watchers with len 1 for now")
if n.watch_list.len > 1 {
return error('only support watchers with len 1 for now')
}
// Start a watcher for each path
for mut entry in n.watch_list {
//spawn n.watch_path(mut entry)
// spawn n.watch_path(mut entry)
n.watch_path(mut entry)
}
}
@@ -114,7 +114,7 @@ fn (mut n Notifier) watch_path(mut entry WatchEntry) {
p.set_args(['-x', '--event-flags', entry.path])
p.set_redirect_stdio()
p.run()
entry.pid = p.pid
for n.is_watching {
@@ -140,7 +140,7 @@ fn (mut n Notifier) watch_path(mut entry WatchEntry) {
}
if cb := entry.callback {
cb(event, path,n.args)
cb(event, path, n.args)
}
}
}