Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
bliss
Commits
348e90a8
Commit
348e90a8
authored
Jul 05, 2021
by
Matias Guijarro
Browse files
fix issue
#2849
: finished work with the prompt toolkit output wrapper, make elog_add working again
parent
1194bb75
Changes
2
Hide whitespace changes
Inline
Side-by-side
bliss/shell/cli/repl.py
View file @
348e90a8
...
...
@@ -219,9 +219,8 @@ class Info:
class
WrappedStdout
:
def
__init__
(
self
,
ptpython_output
,
current_output
):
self
.
_ptpython_output
=
ptpython_output
self
.
_current_output
=
current_output
def
__init__
(
self
,
output_buffer
):
self
.
_buffer
=
output_buffer
self
.
_orig_stdout
=
sys
.
stdout
# context manager
...
...
@@ -231,8 +230,6 @@ class WrappedStdout:
return
self
def
__exit__
(
self
,
*
args
,
**
kwargs
):
self
.
_ptpython_output
.
_output
.
append
(
""
.
join
(
self
.
_current_output
))
self
.
_current_output
.
clear
()
sys
.
stdout
=
self
.
_orig_stdout
# delegated members
...
...
@@ -258,18 +255,16 @@ class WrappedStdout:
def
write
(
self
,
data
):
# wait for stdout to be ready to receive output
if
True
:
# if gevent.select.select([],[self.fileno()], []):
self
.
_
current_output
.
append
(
data
)
self
.
_
buffer
.
append
(
data
)
self
.
_orig_stdout
.
write
(
data
)
# in the next class, inheritance from DummyOutput is just needed
# to make ptpython happy (as there are some asserts checking instance type)
class
PromptToolkitOutputWrapper
(
DummyOutput
):
SIZE
=
20
def
__init__
(
self
,
output
):
self
.
__wrapped_output
=
output
self
.
_
current_output
=
[]
self
.
_
output_buffer
=
[]
self
.
_output
=
deque
(
maxlen
=
20
)
def
__getattr__
(
self
,
attr
):
...
...
@@ -279,17 +274,21 @@ class PromptToolkitOutputWrapper(DummyOutput):
@
property
def
capture_stdout
(
self
):
return
WrappedStdout
(
self
,
self
.
_current_output
)
return
WrappedStdout
(
self
.
_output_buffer
)
def
acknowledge_output
(
self
):
self
.
_output
.
append
(
""
.
join
(
self
.
_output_buffer
))
self
.
_output_buffer
.
clear
()
def
__getitem__
(
self
,
item_no
):
if
item_no
>
=
0
:
if
item_no
>
0
:
# item_no starts at 1 to match "Out" number in ptpython
item_no
-=
1
# if item_no is specified negative => no decrement of number
of course
# if item_no is specified negative
or 0
=> no decrement of number
return
self
.
_output
[
item_no
]
def
write
(
self
,
data
):
self
.
_
current_output
.
append
(
data
)
self
.
_
output_buffer
.
append
(
data
)
self
.
__wrapped_output
.
write
(
data
)
def
fileno
(
self
):
...
...
@@ -358,6 +357,13 @@ class BlissRepl(NoThreadPythonRepl, metaclass=Singleton):
##
# NB: next methods are overloaded
##
async
def
eval_async
(
self
,
text
):
with
self
.
app
.
output
.
capture_stdout
:
result
=
await
super
().
eval_async
(
text
)
if
result
is
None
:
self
.
app
.
output
.
acknowledge_output
()
return
result
def
show_result
(
self
,
result
):
try
:
if
hasattr
(
result
,
"__info__"
):
...
...
@@ -369,6 +375,8 @@ class BlissRepl(NoThreadPythonRepl, metaclass=Singleton):
sys
.
excepthook
(
*
sys
.
exc_info
())
else
:
return
super
().
show_result
(
result
)
finally
:
self
.
app
.
output
.
acknowledge_output
()
def
_handle_keyboard_interrupt
(
self
,
e
:
KeyboardInterrupt
)
->
None
:
sys
.
excepthook
(
*
sys
.
exc_info
())
...
...
bliss/shell/standard.py
View file @
348e90a8
...
...
@@ -1505,11 +1505,11 @@ def elog_add(index=-1):
"""
Send to the logbook given cell output and the print that was
performed during the elaboration.
Only a fixed size of output are kept in memory (normally last
10
0).
Only a fixed size of output are kept in memory (normally last
2
0).
Args:
index (int): Index of the cell to be sent to logbook, can
be positive reflecti
o
ng the prompt index
be positive reflecting the prompt index
or negative.
Default is -1 (previous cell)
...
...
@@ -1522,11 +1522,16 @@ def elog_add(index=-1):
unit = None
mode = MEAN (1)
BLISS [3]: elog_add() # sends last otput from diode
BLISS [3]: elog_add() # sends last o
u
tput from diode
"""
from
bliss.shell.cli.repl
import
CaptureOutput
from
bliss.shell.cli.repl
import
BlissRepl
logtools
.
elogbook
.
comment
(
CaptureOutput
()[
index
])
try
:
comment
=
BlissRepl
().
app
.
output
[
index
]
except
IndexError
:
logtools
.
user_warning
(
f
"Cell output [
{
index
}
] does not exist"
)
else
:
logtools
.
elogbook
.
comment
(
comment
)
@
logtools
.
elogbook
.
disable_command_logging
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment