Ticket #67 (closed defect: fixed)

Opened 8 months ago

Last modified 3 months ago

Ability to run multiple Interact sessions

Reported by: athomas Assigned to: athomas
Priority: major Component: cly
Severity: normal Keywords:
Cc:

Description

It would be nice to be able to start a new interactive session from an action callback, with a limited grammar specific to that command.

This is not currently possible due to the many globals in Interact for readline support, but it should be possible by switching in and out container objects that contain the readline specific globals.

Attachments

Change History

03/27/08 20:59:36 changed by tom

This feature would be really great since one could use it to implement much more serious stuff (e.g. a router OS). The limited grammar should be able to contain the same commands but with a different implementation (e.g. "show" in a global and local context as in the follwing example which also changes the prompt after one action callback (or entering an object in an object hierarchie as I prefer to think of it):

# show users
alec tom john
# user alec
(alec) # set home /home/alec
(alec) # set shell /bin/bash
(alec) # show    <- this will show all properties of the user alec
(alec) # exit
#

This feature is also important to reduce namespace pollution with a flat namespace. I hope you find a solution how to implement it, since this will make a real difference! I looked at many other similar solutions and frameworks and most (or all) failed here.

cly is really nice otherwise!

06/15/08 05:18:56 changed by athomas

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in r554.

06/15/08 05:37:58 changed by athomas

Sample implementation of your scenario:

from cly import *


users = {
    'alec': {'gecos': 'Alec Thomas'},
    'tom': {'gecos': 'Tom Waitaminute'},
    }
    
    
def show_users():
    print ' '.join(users.keys())
    
    
def edit_user(user):
    def set_attribute(attribute, value):
        users[user][attribute] = value
        
    def show_attributes():
        for key, value in users[user].items():
            print key, value
            
    grammar = Grammar(
        set=Node(
            attribute=Word(
                value=Variable(Action(set_attribute), pattern=r'.+'),
                ),  
            ),  
        show=Node(Action(show_attributes)),
        )
        
    interact(grammar, prompt='(%s) ' % user)
    
    
main = Grammar(
    show=Node(
        users=Node(Action(show_users)),
        ),
    user=Node(
        user=Variable(Action(edit_user)),
        ),
    )   
    
interact(main, prompt='# ')

Add/Change #67 (Ability to run multiple Interact sessions)




Change Properties
Action