Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
73468221
Commit
73468221
authored
Jan 07, 2016
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #97 from mruwek/column-ui-history
Add history to command-line widget
parents
5f5a125a
5db3ce13
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
topydo/ui/CommandLineWidget.py
topydo/ui/CommandLineWidget.py
+41
-0
No files found.
topydo/ui/CommandLineWidget.py
View file @
73468221
...
...
@@ -18,6 +18,12 @@ import urwid
class
CommandLineWidget
(
urwid
.
Edit
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
history
=
None
self
.
history_pos
=
None
# temporary history storage for edits before cmd execution
self
.
history_tmp
=
None
super
().
__init__
(
*
args
,
**
kwargs
)
urwid
.
register_signal
(
CommandLineWidget
,
[
'blur'
,
'execute_command'
])
...
...
@@ -30,12 +36,47 @@ class CommandLineWidget(urwid.Edit):
def
_emit_command
(
self
):
urwid
.
emit_signal
(
self
,
'execute_command'
,
self
.
edit_text
)
self
.
_save_to_history
()
self
.
clear
()
def
_save_to_history
(
self
):
if
len
(
self
.
edit_text
)
>
0
:
if
self
.
history
is
None
:
self
.
history
=
[]
self
.
history
.
append
(
self
.
edit_text
)
self
.
history_pos
=
len
(
self
.
history
)
self
.
history_tmp
=
self
.
history
[:]
# sync temporary storage with real history
self
.
history_tmp
.
append
(
''
)
def
_history_move
(
self
,
p_step
):
"""
Changes current value of the command-line to the value obtained from
history_tmp list with index calculated by addition of p_step to the
current position in the command history (history_pos attribute).
Also saves value of the command-line (before changing it) to history_tmp
for potential later access.
"""
if
self
.
history
is
not
None
:
# don't pollute real history - use temporary storage
self
.
history_tmp
[
self
.
history_pos
]
=
self
.
edit_text
self
.
history_pos
=
self
.
history_pos
+
p_step
self
.
set_edit_text
(
self
.
history_tmp
[
self
.
history_pos
])
def
_history_next
(
self
):
if
self
.
history_pos
!=
len
(
self
.
history
):
self
.
_history_move
(
1
)
def
_history_back
(
self
):
if
self
.
history_pos
!=
0
:
self
.
_history_move
(
-
1
)
def
keypress
(
self
,
p_size
,
p_key
):
dispatch
=
{
'enter'
:
self
.
_emit_command
,
'esc'
:
self
.
_blur
,
'up'
:
self
.
_history_back
,
'down'
:
self
.
_history_next
}
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment