# HG changeset patch # User Josef "Jeff" Sipek # Date 1156022595 14400 # Node ID f87b969fa973318fd95f9fc1880740d69a09e271 # Parent 50745af6a63baf1318434ca2bfbec75b69ccd8d6 Little cleanup; change of plans - try to make it more like ed first diff -r 50745af6a63b -r f87b969fa973 vixm/ui.py --- a/vixm/ui.py Fri Aug 18 20:32:00 2006 -0400 +++ b/vixm/ui.py Sat Aug 19 17:23:15 2006 -0400 @@ -45,30 +45,72 @@ util.strtime(s["time"])) self.lists[playlist.LIST_PRIO].enqueue(s) + def __list(self, cmd, parts): + i = 1 + + if len(parts) > 1: + try: + listid = int(parts[1]) + if listid < 0 or listid >= len(self.lists): + raise ValueError + except: + print "Invalid list number" + return + else: + listid = playlist.LIST_PRIO + + for s in self.lists[listid]: + print "%d. %s (%s)" % (i, s["title"], + util.strtime(s["time"])) + i += 1 + def __cmd(self, txt): parts = txt.split() cmd = parts[0] + # commad list: + # quit 'q[!]' + # quit fails if there are list changes in + # memory that haven't been saved. The optional + # '!' forces the quit + # + # number '[range]n [playlistid]' + # prints playlist [playlistid] (default is + # LIST_PRIO) with each entry being numbered. + # If optional range is supplied, only the + # songs in that range are printed. The range + # string is standard ed-like line range (see + # below for details) + # + # list '[range]l [playlistid]' + # virtually identical to the number command + # above, however the lines are not numbered. + # The same rules apply to the range and + # playlistid arguments + # + # enqueue 'a songid' + # enqueue a song songid from LIST_DEFAULT onto + # LIST_PRIO. The enqueued song is added to the + # end of LIST_PRIO + # + # dequeue 'd songid' + # remove songid from LIST_PRIO. The songid is + # the id in LIST_PRIO, NOT LIST_DEFAULT + # + # range: + # '' first entry; shortcut for '1' + # '%' entire list; shortcut for '1,$' + # '$' last entry + # 'n' entry on line n + # 'm,n' range of entries starting on line m and + # ending on line n. Both m and n are included + # in the list. m or n can both be an integer, + # '' or '$'. + if cmd == "quit": self.shutdown = True elif cmd == "list": - i = 1 - - if len(parts) > 1: - try: - listid = int(parts[1]) - if listid < 0 or listid >= len(self.lists): - raise ValueError - except: - print "Invalid list number" - return - else: - listid = playlist.LIST_PRIO - - for s in self.lists[listid]: - print "%d. %s (%s)" % (i, s["title"], - util.strtime(s["time"])) - i += 1 + self.__list(cmd, parts) elif cmd == "lists": print "#0 LIST_PRIO" print "#1 LIST_DEFAULT" @@ -79,18 +121,23 @@ while not self.shutdown: tmp = sys.stdin.readline().strip() - if tmp.startswith(":"): - # ':NNN' + # FIXME: we should use regexps for this + # + # search: '^\/(.+)' + # enqueue: '^([0-9]+)' + # commands: '^([A-Za-z]+)(([^ ]*) *)*' + + if tmp.startswith("/"): + # '/ABC' - searching + print "Searching not yet implemented" + else: + # 'ABC' - commands and enqueues try: id = int(tmp[1:]) except: self.__cmd(tmp[1:]) continue + + # we got something numeric, let's enqueue self.__enqueue(id) - elif tmp.startswith("/"): - # '/ABC' - print "Searching not yet implemented" - else: - print "Unable to parse command \"%s\"" % (tmp,) -