Some adjustments of the formatting for auto_help. Added some colours to the state_example menu.

This commit is contained in:
Griatch 2009-05-02 08:25:37 +00:00
parent cafbdf720e
commit fd050f75ca
3 changed files with 14 additions and 15 deletions

View file

@ -72,7 +72,6 @@ def menu_cmd_option2(command):
""" """
option2 option2
This selects the second option. Duh. This selects the second option. Duh.
<<TOPIC:About>> <<TOPIC:About>>
This is an extra topic to test the auto_help functionality. This is an extra topic to test the auto_help functionality.
""" """
@ -95,13 +94,13 @@ def print_menu(source_obj,choice=None):
would happen here in a real menu. would happen here in a real menu.
""" """
if choice==1: if choice==1:
ch = "> option1\n option2" ch = "%s> option1\n %soption2" % ('%ch%cy','%cn%cy') #ansi colouring; see src.ansi
elif choice==2: elif choice==2:
ch = " option1\n> option2" ch = " %soption1\n%s> option2" % ('%cn%cy','%ch%cy')
else: else:
ch = " option1\n option2" ch = " %soption1\n option2" % ('%cn%cy')
s ="Menu---------\n%s\n help - get help" % ch s ="%sMenu---------\n%s\n %shelp - get help" % ('%ch%cr',ch,'%cn%cy')
source_obj.emit_to(s) source_obj.emit_to(s)

View file

@ -78,10 +78,10 @@ def handle_help_markup(topicstr, entrytext, staff_only, identifier="<<TOPIC:"):
topic_dict = {} topic_dict = {}
staff_dict = {} staff_dict = {}
for txt in topic_list: for txt in topic_list:
txt = txt.strip() txt = txt.rstrip()
if txt.count('>>'): if txt.count('>>'):
topic, text = txt.split('>>',1) topic, text = txt.split('>>',1)
text = text.strip() text = text.rstrip()
topic = topic.lower() topic = topic.lower()
if topic in topic_dict.keys(): if topic in topic_dict.keys():
@ -99,7 +99,7 @@ def handle_help_markup(topicstr, entrytext, staff_only, identifier="<<TOPIC:"):
else: else:
#no markup, just add the entry as-is #no markup, just add the entry as-is
topic = topicstr.lower() topic = topicstr.lower()
topic_dict[topic] = '\r\n' + txt topic_dict[topic] = txt
staff_dict[topic] = staff_only staff_dict[topic] = staff_only
return topic_dict, staff_dict return topic_dict, staff_dict
@ -119,14 +119,13 @@ def format_footer(top, text, topic_dict, staff_dict):
other_topics = other_topics = filter(lambda o: o != top and not staff_dict[o], other_topics = other_topics = filter(lambda o: o != top and not staff_dict[o],
topic_dict.keys()) topic_dict.keys())
if other_topics: if other_topics:
footer = ANSITable.ansi['normal'] + "\n\r Related Topics: " footer = ANSITable.ansi['normal'] + "\n\r\n\r Related Topics: "
for t in other_topics: for t in other_topics:
footer += t + ', ' footer += t + ', '
footer = footer[:-2] + '.' footer = footer[:-2] + '.'
return text + footer return text + footer
else: else:
return text return text
else: else:
return False return False

View file

@ -135,6 +135,7 @@ class StateHelpIndex(object):
Supports <<TOPIC:MyTopic>> and <<TOPIC:STAFF:MyTopic>> markup.""" Supports <<TOPIC:MyTopic>> and <<TOPIC:STAFF:MyTopic>> markup."""
if self.help_index.has_key(state): if self.help_index.has_key(state):
text = text.rstrip()
if self.identifier in text: if self.identifier in text:
topic_dict, staff_dict = edit_help.handle_help_markup(command, text, staff_only, topic_dict, staff_dict = edit_help.handle_help_markup(command, text, staff_only,
identifier=self.identifier) identifier=self.identifier)
@ -210,10 +211,10 @@ def cmd_state_help(command):
if not index: if not index:
source_object.emit_to("There is no help available here.") source_object.emit_to("There is no help available here.")
return return
s = "Help topics for %s:\n" % state s = "Help topics for %s:\n\r" % state
for i in index: for i in index:
s += " %s\n" % i s += " %s\n\r" % i
s = s[:-1] s = s[:-2]
source_object.emit_to(s) source_object.emit_to(s)
return return
else: else: