comparison vixm/ui.py @ 7:f87b969fa973

Little cleanup; change of plans - try to make it more like ed first
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sat, 19 Aug 2006 17:23:15 -0400
parents 50745af6a63b
children 79340745c952
comparison
equal deleted inserted replaced
6:50745af6a63b 7:f87b969fa973
43 s = self.lists[playlist.LIST_DEFAULT][id] 43 s = self.lists[playlist.LIST_DEFAULT][id]
44 print "Enqueuing song: %d. %s (%s)" % (id, s["title"], 44 print "Enqueuing song: %d. %s (%s)" % (id, s["title"],
45 util.strtime(s["time"])) 45 util.strtime(s["time"]))
46 self.lists[playlist.LIST_PRIO].enqueue(s) 46 self.lists[playlist.LIST_PRIO].enqueue(s)
47 47
48 def __list(self, cmd, parts):
49 i = 1
50
51 if len(parts) > 1:
52 try:
53 listid = int(parts[1])
54 if listid < 0 or listid >= len(self.lists):
55 raise ValueError
56 except:
57 print "Invalid list number"
58 return
59 else:
60 listid = playlist.LIST_PRIO
61
62 for s in self.lists[listid]:
63 print "%d. %s (%s)" % (i, s["title"],
64 util.strtime(s["time"]))
65 i += 1
66
48 def __cmd(self, txt): 67 def __cmd(self, txt):
49 parts = txt.split() 68 parts = txt.split()
50 cmd = parts[0] 69 cmd = parts[0]
51 70
71 # commad list:
72 # quit 'q[!]'
73 # quit fails if there are list changes in
74 # memory that haven't been saved. The optional
75 # '!' forces the quit
76 #
77 # number '[range]n [playlistid]'
78 # prints playlist [playlistid] (default is
79 # LIST_PRIO) with each entry being numbered.
80 # If optional range is supplied, only the
81 # songs in that range are printed. The range
82 # string is standard ed-like line range (see
83 # below for details)
84 #
85 # list '[range]l [playlistid]'
86 # virtually identical to the number command
87 # above, however the lines are not numbered.
88 # The same rules apply to the range and
89 # playlistid arguments
90 #
91 # enqueue 'a songid'
92 # enqueue a song songid from LIST_DEFAULT onto
93 # LIST_PRIO. The enqueued song is added to the
94 # end of LIST_PRIO
95 #
96 # dequeue 'd songid'
97 # remove songid from LIST_PRIO. The songid is
98 # the id in LIST_PRIO, NOT LIST_DEFAULT
99 #
100 # range:
101 # '' first entry; shortcut for '1'
102 # '%' entire list; shortcut for '1,$'
103 # '$' last entry
104 # 'n' entry on line n
105 # 'm,n' range of entries starting on line m and
106 # ending on line n. Both m and n are included
107 # in the list. m or n can both be an integer,
108 # '' or '$'.
109
52 if cmd == "quit": 110 if cmd == "quit":
53 self.shutdown = True 111 self.shutdown = True
54 elif cmd == "list": 112 elif cmd == "list":
55 i = 1 113 self.__list(cmd, parts)
56
57 if len(parts) > 1:
58 try:
59 listid = int(parts[1])
60 if listid < 0 or listid >= len(self.lists):
61 raise ValueError
62 except:
63 print "Invalid list number"
64 return
65 else:
66 listid = playlist.LIST_PRIO
67
68 for s in self.lists[listid]:
69 print "%d. %s (%s)" % (i, s["title"],
70 util.strtime(s["time"]))
71 i += 1
72 elif cmd == "lists": 114 elif cmd == "lists":
73 print "#0 LIST_PRIO" 115 print "#0 LIST_PRIO"
74 print "#1 LIST_DEFAULT" 116 print "#1 LIST_DEFAULT"
75 else: 117 else:
76 print "Invalid command \"%s\"" % (cmd,) 118 print "Invalid command \"%s\"" % (cmd,)
77 119
78 def run(self): 120 def run(self):
79 while not self.shutdown: 121 while not self.shutdown:
80 tmp = sys.stdin.readline().strip() 122 tmp = sys.stdin.readline().strip()
81 123
82 if tmp.startswith(":"): 124 # FIXME: we should use regexps for this
83 # ':NNN' 125 #
126 # search: '^\/(.+)'
127 # enqueue: '^([0-9]+)'
128 # commands: '^([A-Za-z]+)(([^ ]*) *)*'
129
130 if tmp.startswith("/"):
131 # '/ABC' - searching
132 print "Searching not yet implemented"
133 else:
134 # 'ABC' - commands and enqueues
84 try: 135 try:
85 id = int(tmp[1:]) 136 id = int(tmp[1:])
86 except: 137 except:
87 self.__cmd(tmp[1:]) 138 self.__cmd(tmp[1:])
88 continue 139 continue
140
141 # we got something numeric, let's enqueue
89 self.__enqueue(id) 142 self.__enqueue(id)
90 143
91 elif tmp.startswith("/"):
92 # '/ABC'
93 print "Searching not yet implemented"
94 else:
95 print "Unable to parse command \"%s\"" % (tmp,)
96