Re: Definite menu code rewrite
On Wed, 17 Jul 2002, Chris Lawrence <lawrencc@debian.org> wrote:
> 7. New code to replace /etc/menu-methods will have to be written.
> This may be the most challenging part of the project. The upside
> is that not many of these need to be written, and I hope to come up
> with something much easier to use than the bizarre language
> install-menus uses.
Though "he who makes the code makes the rules", let me nonetheless
offer my votes: either Python (preferable) or Perl. In both cases,
you have no need to document the *syntax* someone with way more
time and (without offering any insult) way more competent has done
it. Let me even suggest that instead of dictating a language, just
offer either a Perl or a Python library doing most of the stuff.
So, a common menu-method (say, for ZWM) might look like
#!/usr/bin/python
import debmenu
def _escape(self, s):
return s.replace('"', '\\"')
class ZWMMenuGenerator(debmenu.MenuGenerator):
def start_menu(self):
self.out('Menu(')
def start_submenu(self, submenuName):
self.out('Submenu("' + _escape(subMenuName)+'",')
def end_submenu(self):
self.out('),')
def do_item(self, item):
self.out('Item("%s", "%s"),' % (_escape(item.command),
_escape(item.name)))
def end_menu(self):
self.out(')')
if __name__ == '__main__':
demenu.main(ZWMMenuGenerator)
or (were I insane enough to write in Perl):
#!/usr/bin/perl
sub escape {
my $s = $_[0];
$s =~ s/"/\\"/;
}
package ZWMenuGenerator;
@ISA = ('debmenu::MenuGenerator');
sub start_menu {
$_[0]->out('Menu(');
}
sub start_submenu {
$_[0]->out('Submenu("' . escape($_[1]) . '",');
}
sub end_submenu {
$_[0]->out(')')
}
sub do_item {
$_[0]->out('Item("' escape($_[1]->command) . '", "'
. escape($_[1]->name) . '"),')
}
sub end_menu {
$_[0]->out(')')
}
debmenu::main('ZWMMenuGenerator')
(both contain probably contain bugs, and are meant only as proof of concept.
Especially flames about how godawful my Perl is, or how I don't know the
first thing about OO Perl, will be redirected to /dev/null)
--
To UNSUBSCRIBE, email to debian-devel-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Reply to: