mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
some minor changes
This commit is contained in:
parent
d2cd3388bd
commit
bc18074ab8
2 changed files with 12 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""The base class for xonsh shell"""
|
"""The base class for xonsh shell"""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import builtins
|
import builtins
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -38,12 +39,20 @@ class BaseShell(object):
|
||||||
code = self.push(line)
|
code = self.push(line)
|
||||||
if code is None:
|
if code is None:
|
||||||
return
|
return
|
||||||
|
ts1 = None
|
||||||
|
#outstart = sys.stdout.tell()
|
||||||
try:
|
try:
|
||||||
|
ts0 = time.time()
|
||||||
self.execer.exec(code, mode='single', glbs=self.ctx) # no locals
|
self.execer.exec(code, mode='single', glbs=self.ctx) # no locals
|
||||||
|
ts1 = time.time()
|
||||||
except XonshError as e:
|
except XonshError as e:
|
||||||
print(e.args[0], file=sys.stderr)
|
print(e.args[0], file=sys.stderr)
|
||||||
except:
|
except:
|
||||||
_print_exception()
|
_print_exception()
|
||||||
|
finally:
|
||||||
|
ts1 = ts1 or time.time()
|
||||||
|
hist = builtins.__xonsh_history__
|
||||||
|
hist.append({'inp': line, 'ts': [ts0, ts1]})
|
||||||
if builtins.__xonsh_exit__:
|
if builtins.__xonsh_exit__:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -72,9 +81,6 @@ class BaseShell(object):
|
||||||
self.reset_buffer()
|
self.reset_buffer()
|
||||||
_print_exception()
|
_print_exception()
|
||||||
return None
|
return None
|
||||||
finally:
|
|
||||||
hist = builtins.__xonsh_history__
|
|
||||||
hist.append({'inp': src})
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def reset_buffer(self):
|
def reset_buffer(self):
|
||||||
|
@ -135,3 +141,5 @@ def _print_exception():
|
||||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
exception_only = traceback.format_exception_only(exc_type, exc_value)
|
exception_only = traceback.format_exception_only(exc_type, exc_value)
|
||||||
sys.stderr.write(''.join(exception_only))
|
sys.stderr.write(''.join(exception_only))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""Implements the xonsh history object"""
|
"""Implements the xonsh history object"""
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import uuid
|
import uuid
|
||||||
import builtins
|
import builtins
|
||||||
from threading import Thread, Condition
|
from threading import Thread, Condition
|
||||||
|
@ -76,15 +75,13 @@ class History(object):
|
||||||
lazyjson.dump(meta, f, sort_keys=True)
|
lazyjson.dump(meta, f, sort_keys=True)
|
||||||
|
|
||||||
def append(self, cmd):
|
def append(self, cmd):
|
||||||
"""Adds command with current timestamp to ordered history. Will periodically
|
"""Appends command to history. Will periodically flush the history to file.
|
||||||
flush the history to file.
|
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
cmd : dict
|
cmd : dict
|
||||||
Command dictionary that should be added to the ordered history.
|
Command dictionary that should be added to the ordered history.
|
||||||
"""
|
"""
|
||||||
cmd['timestamp'] = time.time()
|
|
||||||
self.buffer.append(cmd)
|
self.buffer.append(cmd)
|
||||||
if len(self.buffer) >= self.buffersize:
|
if len(self.buffer) >= self.buffersize:
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
Loading…
Add table
Reference in a new issue