简体   繁体   中英

context sensitive completion lists for python readline

I ask a user for a string of cypher and use readline tab autocomplete to provide options, but would like to use several different option lists depending on which bit of the cypher statement it is.

A simplified cypher string looks like this:

(node_name:LABEL1:LABEL2 {key1: value1, key2: value2})

What I would like is to have one completion list for labels, and a dictionary of lists of values for each of the different property keys eg:

{key1: [option1, option2, option3], key2: [foo, bar, baz]}

Is there a way to have newline (or other similar library) know where it is in a cypher string so that it only displays options from the label list when it is in the label position and only options from the appropriate key list when the user is writing the properties.

Edit: This page gives an example of using a regular grammar with readline. It seems to answer my question so I'm marking this answered.

Have a look at the rlcompleter module in teh python standard library. I used this technique myself recently. See ( example ): https://bitbucket.org/prologic/mio-lang/src/tip/mio/state.py#cl-30

网页介绍如何使用与readline的常规语法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM