Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sjrpc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
sjrpc
Commits
4da970f7
Commit
4da970f7
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
Abstract readline completer by a simple completer which take a list of choice
parent
14791a44
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cccli/cli.py
+4
-8
4 additions, 8 deletions
cccli/cli.py
cccli/printer.py
+16
-2
16 additions, 2 deletions
cccli/printer.py
with
20 additions
and
10 deletions
cccli/cli.py
+
4
−
8
View file @
4da970f7
...
...
@@ -51,7 +51,7 @@ class Cli(object):
self
.
printer
.
history
.
maxsize
(
self
.
settings
.
get
(
"
hsize
"
,
None
))
self
.
printer
.
debug
(
"
Loaded history: %s
"
%
len
(
self
.
printer
.
history
))
# enable completion
self
.
printer
.
completion
.
set_completer
(
self
.
_completer
)
self
.
printer
.
completion
.
set_completer
(
self
.
_
command_
completer
)
# set prompt
# load alias
self
.
alias
.
load
(
self
.
settings
.
get
(
"
alias
"
,
""
))
...
...
@@ -155,17 +155,13 @@ class Cli(object):
self
.
printer
.
error
(
"
%s: %s
"
%
(
type
(
e
),
str
(
e
)))
self
.
printer
.
warn
(
"
This is a not expected error, please report it!
"
)
def
_completer
(
self
,
texte
,
state
):
def
_command
_completer
(
self
,
texte
):
'''
Return the list of completion
'''
comp
=
self
.
printer
.
completion
stripped
=
comp
.
get_buf
()[:
comp
.
get_begin
()
+
1
].
lstrip
()
if
state
==
0
and
texte
==
""
and
stripped
!=
""
:
if
texte
==
""
and
stripped
!=
""
:
return
None
cl
=
[
c
for
c
in
Command
.
list
()
if
c
.
startswith
(
texte
)
]
if
state
<
len
(
cl
):
return
cl
[
state
]
return
None
return
[
c
for
c
in
Command
.
list
()
if
c
.
startswith
(
texte
)
]
class
CliHandler
(
RpcHandler
):
'''
Handle RPC incoming request
'''
...
...
This diff is collapsed.
Click to expand it.
cccli/printer.py
+
16
−
2
View file @
4da970f7
...
...
@@ -220,6 +220,8 @@ class Completion(object):
'''
Handle completion functions
'''
def
__init__
(
self
):
self
.
readline
=
None
self
.
compfunc
=
None
self
.
complist
=
list
()
def
__getattribute__
(
self
,
name
):
r
=
object
.
__getattribute__
(
self
,
"
readline
"
)
...
...
@@ -241,7 +243,19 @@ class Completion(object):
'''
Get the ending index of the readline tab-completion scope
'''
return
self
.
readline
.
get_begidx
()
def
_completer
(
self
,
text
,
state
):
'''
Readline real completer
'''
if
state
==
0
:
if
self
.
compfunc
is
not
None
:
self
.
complist
=
list
(
self
.
compfunc
(
text
))
try
:
return
self
.
complist
[
state
]
except
IndexError
:
self
.
complist
=
list
()
return
None
def
set_completer
(
self
,
func
):
'''
Set completer function
'''
self
.
readline
.
set_completer
(
func
)
'''
Set completer custom function which return a list of possibilities
'''
self
.
compfunc
=
func
self
.
readline
.
set_completer
(
self
.
_completer
)
self
.
readline
.
parse_and_bind
(
"
tab: complete
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment