Skip to content

Commit

Permalink
Merge pull request #93 from andfoy/cwd_initialization
Browse files Browse the repository at this point in the history
PR: Simplify initialization routine
  • Loading branch information
andfoy committed Jul 17, 2017
2 parents 45594b4 + 6fa2f7d commit faf9a24
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 33 deletions.
16 changes: 8 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ environment:
APPVEYOR_RDP_PASSWORD: "dcca4c4863E30d56c2e0dda6327370b3#"

matrix:
- PYTHON_VERSION: "3.6"
PYTHON_ARCH: "32"
ARCH: "x86"
platform: "x86"
# - PYTHON_VERSION: "3.6"
# PYTHON_ARCH: "32"
# ARCH: "x86"
# platform: "x86"
- PYTHON_VERSION: "3.5"
PYTHON_ARCH: "32"
ARCH: "x86"
Expand All @@ -26,10 +26,10 @@ environment:
PYTHON_ARCH: "64"
ARCH: "amd64"
platform: "x64"
- PYTHON_VERSION: "3.5"
PYTHON_ARCH: "64"
ARCH: "amd64"
platform: "x64"
# - PYTHON_VERSION: "3.5"
# PYTHON_ARCH: "64"
# ARCH: "amd64"
# platform: "x64"

platform:
-x64
Expand Down
6 changes: 3 additions & 3 deletions spyder_terminal/server/logic/term_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def __init__(self, cmd):
self.consoles = {}

@tornado.gen.coroutine
def create_term(self, rows, cols):
def create_term(self, rows, cols, cwd=None):
"""Create a new virtual terminal."""
pid = hashlib.md5(str(time.time()).encode('utf-8')).hexdigest()[0:6]
if WINDOWS:
tty = pty.PTY(cols, rows)
tty.spawn(self.cmd)
tty.spawn(self.cmd, cwd=cwd)
else:
tty = pty.spawnu(self.cmd)
tty = pty.spawnu(self.cmd, cwd=cwd)
tty.setwinsize(rows, cols)
self.consoles[pid] = {'tty': tty, 'read': None}
raise tornado.gen.Return(pid)
Expand Down
5 changes: 4 additions & 1 deletion spyder_terminal/server/rest/term_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import tornado.web
import tornado.escape
from os import getcwd


class MainHandler(tornado.web.RequestHandler):
Expand All @@ -14,7 +15,9 @@ def post(self):
"""POST verb: Create a new terminal."""
rows = int(self.get_argument('rows', None, 23))
cols = int(self.get_argument('cols', None, 73))
pid = yield self.application.term_manager.create_term(rows, cols)
cwd = self.get_cookie('cwd', default=getcwd())
self.application.logger.info('CWD: {0}'.format(cwd))
pid = yield self.application.term_manager.create_term(rows, cols, cwd)
self.write(pid)


Expand Down
26 changes: 11 additions & 15 deletions spyder_terminal/server/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ window.onresize = function(event) {
}


createTerminal();

function createTerminal() {
console.log("Creating term...");
// Clean terminal
Expand Down Expand Up @@ -70,7 +68,11 @@ function createTerminal() {
console.log(rows);


fetch('/api/terminals?cols=' + cols + '&rows=' + rows, {method: 'POST', headers: myHeaders}).then(function (res) {
fetch('/api/terminals?cols=' + cols + '&rows=' + rows, {
method: 'POST',
headers: myHeaders,
credentials: 'include'
}).then(function (res) {

charWidth = Math.ceil(term.element.offsetWidth / cols);
charHeight = Math.ceil(term.element.offsetHeight / rows);
Expand Down Expand Up @@ -142,18 +144,12 @@ function scrollTerm(delta) {
function runRealTerminal() {
term.attach(socket);
term._initialized = true;
term.writeln("Loading...");
// term.writeln("Loading...");
lineEnd = term.browser.isMSWindows ? '\r\n' : '\n';
clearCmd = term.browser.isMSWindows ? 'cls' : 'clear';

var initialX = term.x;
var timer = setInterval(function() {
if(term.x != initialX) {
term.clear();
chdir(path);
clearTerm();
fitFont(curFont);
clearInterval(timer);
}
}, 200);
fitFont(curFont);
}

$(document).ready(function() {
createTerminal();
});
3 changes: 3 additions & 0 deletions spyder_terminal/server/web/main_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import tornado.web
import tornado.escape
from os import getcwd


class MainHandler(tornado.web.RequestHandler):
Expand All @@ -16,6 +17,8 @@ def initialize(self, db=None):
@tornado.gen.coroutine
def get(self):
"""Get static index.html page."""
cwd = self.get_argument('path', getcwd())
self.set_cookie('cwd', cwd)
self.render('../static/index.html')

@tornado.gen.coroutine
Expand Down
9 changes: 4 additions & 5 deletions spyder_terminal/server/websockets/term_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ def initialize(self, close_future=None):

def open(self, pid):
"""Open a Websocket associated to a console."""
print("WebSocket opened")
print(pid)
self.application.logger.info("WebSocket opened: {0}".format(pid))
self.pid = pid
self.application.term_manager.start_term(pid, self)
print("TTY On!")
self.application.logger.info("TTY On!")

def on_close(self):
"""Close console communication."""
print('TTY Off!')
print("WebSocket closed")
self.application.logger.info('TTY Off!')
self.application.logger.info("WebSocket closed: {0}".format(self.pid))
self.application.term_manager.stop_term(self.pid)
if self.close_future is not None:
self.close_future.set_result(("Done!"))
Expand Down
2 changes: 1 addition & 1 deletion spyder_terminal/widgets/terminalgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TerminalWidget(QFrame):
def __init__(self, parent, port, path='~', font=None):
"""Frame main constructor."""
QWidget.__init__(self, parent)
url = 'http://127.0.0.1:{0}'.format(port)
url = 'http://127.0.0.1:{0}?path={1}'.format(port, path)
self.view = TermView(self, term_url=url)
self.font = font
self.initial_path = path
Expand Down

0 comments on commit faf9a24

Please sign in to comment.