]> njoseph.me Git - nimcoon.git/blobdiff - src/lib.nim
Make options a dictionary and add validation
[nimcoon.git] / src / lib.nim
index 53c2e5d5a98bbde84372d82a0f4f7dd62a21c459..83154737295ab7f25e9d5957245591cd3f550a7e 100644 (file)
@@ -8,6 +8,7 @@ import
   std/[terminal],
   strtabs,
   strutils,
+  tables,
   uri,
   xmltree
 
@@ -15,7 +16,8 @@ import config
 
 type
   SearchResult* = tuple[title: string, url: string]
-  CommandLineOptions* = tuple[searchQuery: string, musicOnly: bool, feelingLucky: bool, fullScreen: bool]
+  Options* = Table[string, bool]
+  CommandLineOptions* = tuple[searchQuery: string, options: Options]
 
 let processOptions = {poStdErrToStdOut, poUsePath}
 
@@ -40,7 +42,7 @@ func extractTitlesAndUrls*(html: string): seq[SearchResult] =
       map(a => (a.attrs["title"], "https://www.youtube.com" & a.attrs["href"]))
 
 proc presentVideoOptions*(searchResults: seq[SearchResult]) =
-  echo ""
+  eraseScreen()
   for index, (title, url) in searchResults:
     styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, url, "\n"