kopia lustrzana https://github.com/c9/core
add a way to list all open tmux sessions
rodzic
f5b3d75a36
commit
f2aea088aa
|
@ -1673,7 +1673,26 @@ module.exports = function setup(fsOptions) {
|
|||
var tmuxName = options.tmuxName || TMUXNAME;
|
||||
var session = options.session;
|
||||
|
||||
function fetchPid(callback, retries){
|
||||
function getFormatString(map) {
|
||||
return Object.keys(map).filter(function(x) {
|
||||
return x[0] == "#";
|
||||
}).join("\x01");
|
||||
}
|
||||
|
||||
function getFormatObject(map, str) {
|
||||
var data = str.split("\x01");
|
||||
var result = {};
|
||||
Object.keys(map).forEach(function(key, i) {
|
||||
if (key[0] != "#") return;
|
||||
var val = data[i];
|
||||
if (i >= map.numberDataIndex)
|
||||
val = parseInt(val, 10) || 0;
|
||||
result[map[key]] = val;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function fetchPid(callback, retries) {
|
||||
if (!retries) retries = 0;
|
||||
_execFile(TMUX, [
|
||||
"-u2", "-L", tmuxName, "-C",
|
||||
|
@ -1681,7 +1700,7 @@ module.exports = function setup(fsOptions) {
|
|||
"-t", session
|
||||
], {
|
||||
maxBuffer: 1000 * 1024
|
||||
}, function(err, stdout){
|
||||
}, function(err, stdout) {
|
||||
var matches = /c9-pid-(\d+)-(\d)-/.exec(stdout);
|
||||
var isDead = parseInt(matches && matches[2], 10);
|
||||
var pid = isDead ? 0 : parseInt(matches && matches[1], 10);
|
||||
|
@ -1701,6 +1720,7 @@ module.exports = function setup(fsOptions) {
|
|||
if (options.fetchpid)
|
||||
return fetchPid(callback);
|
||||
|
||||
|
||||
// Capture the scrollback of a pane
|
||||
if (options.capturePane) {
|
||||
options = options.capturePane;
|
||||
|
@ -1734,7 +1754,35 @@ module.exports = function setup(fsOptions) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (options.getStatus) {
|
||||
if (options.listSessions) {
|
||||
args = ["-u2", "-L", tmuxName];
|
||||
|
||||
var sessionFormat = {
|
||||
"#S": "name",
|
||||
"#{session_id}": "id",
|
||||
"#{session_attached}": "clientCount",
|
||||
"#{session_activity}": "activity",
|
||||
"#{session_created}": "created",
|
||||
"#{session_height}": "height",
|
||||
"#{session_width}": "width",
|
||||
numberDataIndex: 2,
|
||||
};
|
||||
|
||||
args.push("list-sessions", "-F", getFormatString(sessionFormat));
|
||||
|
||||
return _execFile(TMUX, args, function(e, data) {
|
||||
var sessions = [];
|
||||
(data || "").split("\n").forEach(function(str) {
|
||||
if (!str)
|
||||
return;
|
||||
var session = getFormatObject(sessionFormat, str);
|
||||
sessions.push(session);
|
||||
});
|
||||
callback(e, {sessions: sessions});
|
||||
});
|
||||
}
|
||||
|
||||
else if (options.getStatus) {
|
||||
options = options.getStatus;
|
||||
var sessionId = options.id;
|
||||
var args = ["-u2", "-L", tmuxName];
|
||||
|
@ -1764,23 +1812,6 @@ module.exports = function setup(fsOptions) {
|
|||
"#{client_height}" : "height",
|
||||
numberDataIndex : 1,
|
||||
};
|
||||
function getFormatString(map) {
|
||||
return Object.keys(map).filter(function(x) {
|
||||
return x[0] == "#";
|
||||
}).join("\x01");
|
||||
}
|
||||
function getFormatObject(map, str) {
|
||||
var data = str.split("\x01");
|
||||
var result = {};
|
||||
Object.keys(map).forEach(function(key, i) {
|
||||
if (key[0] != "#") return;
|
||||
var val = data[i];
|
||||
if (i >= map.numberDataIndex)
|
||||
val = parseInt(val, 10);
|
||||
result[map[key]] = val;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
args.push("list-panes", "-F", getFormatString(paneFormat));
|
||||
if (sessionId)
|
||||
|
@ -1821,7 +1852,7 @@ module.exports = function setup(fsOptions) {
|
|||
}
|
||||
|
||||
// Kill the session with the same name before starting a new one
|
||||
if (options.kill) {
|
||||
else if (options.kill) {
|
||||
if (!options.session)
|
||||
return callback(new Error("Missing session name"));
|
||||
|
||||
|
|
|
@ -880,6 +880,7 @@ define(function(require, exports, module) {
|
|||
}
|
||||
|
||||
function updateReloadLastButton() {
|
||||
if (!btnReloadLast) return;
|
||||
var last = getLastReloaded();
|
||||
if (last) {
|
||||
btnReloadLast.visible = true;
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<a:application xmlns:a="http://ajax.org/2005/aml">
|
||||
<a:menu id="mnuTerminal">
|
||||
<a:item command="openterminal">New Terminal Tab</a:item>
|
||||
<a:divider />
|
||||
<a:item command="copy">Copy</a:item>
|
||||
<a:item command="paste">Paste</a:item>
|
||||
<a:item command="selectall">Select All</a:item>
|
||||
<a:item command="clearterm">Clear Buffer</a:item>
|
||||
<a:divider />
|
||||
<a:item command="close_term_pane">Close Active Pane</a:item>
|
||||
<a:item command="split_term_pane">Split Active Pane</a:item>
|
||||
<a:divider />
|
||||
<a:item command="layout_term_hor_even">Horizontal Layout (even)</a:item>
|
||||
<a:item command="layout_term_ver_even">Vertical Layout (even)</a:item>
|
||||
<a:item command="layout_term_hor_main">Horizonal Layout (main)</a:item>
|
||||
<a:item command="layout_term_ver_main">Vertical Layout (main)</a:item>
|
||||
<a:divider />
|
||||
<a:item command="toggle_term_status">Toggle Status Bar</a:item>
|
||||
<a:divider />
|
||||
<a:item command="term_restart">Restart All Terminal Sessions</a:item>
|
||||
<a:item command="term_detach">Detach Other Clients</a:item>
|
||||
<a:item command="term_help">Show More Terminal Commands...</a:item>
|
||||
<a:item disabled="true">Hint: Use Alt To Toggle Mouse Mode</a:item>
|
||||
</a:menu>
|
||||
</a:application>
|
|
@ -29,7 +29,6 @@ define(function(require, exports, module) {
|
|||
// Disabled: bad performance, openshift specific, possibly unreliable
|
||||
// var Monitor = require("./monitor.js");
|
||||
var markup = require("text!./terminal.xml");
|
||||
var markupMenu = require("text!./menu.xml");
|
||||
var Aceterm = require("./aceterm/aceterm");
|
||||
var libterm = require("./aceterm/libterm");
|
||||
|
||||
|
@ -368,15 +367,90 @@ define(function(require, exports, module) {
|
|||
});
|
||||
|
||||
handle.draw = function() {
|
||||
ui.insertMarkup(null, markupMenu, handle);
|
||||
mnuTerminal = handle.getElement("mnuTerminal");
|
||||
|
||||
if (c9.platform == "win32") {
|
||||
var nodes = mnuTerminal.childNodes;
|
||||
while (nodes[6]) {
|
||||
mnuTerminal.removeChild(nodes[6]);
|
||||
menus.addItemByPath("context/terminal/", new ui.menu(), handle);
|
||||
var c = 100;
|
||||
menus.addItemByPath("context/terminal/New Terminal Tab", new ui.item({ command: "openterminal" }), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/~", new ui.divider({}), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Copy", new ui.item({ command: "copy" }), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Paste", new ui.item({ command: "paste" }), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Select All", new ui.item({ command: "selectall" }), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Clear Buffer", new ui.item({ command: "clearterm" }), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/~", new ui.divider({}), c += 100, handle);
|
||||
var SESSIONS_MENU = "context/terminal/Other sessions/";
|
||||
menus.addItemByPath(SESSIONS_MENU, new ui.menu({
|
||||
"onprop.visible": function(e) {
|
||||
if (e.value) {
|
||||
var currentName = tabs.focussedTab.document.getSession().id;
|
||||
proc.tmux("", { listSessions: true }, function(err, pty, pid, meta) {
|
||||
menus.remove(SESSIONS_MENU);
|
||||
if (err) {
|
||||
menus.addItemByPath(SESSIONS_MENU + "Error loading session list:(",
|
||||
new ui.item({ disabled: true }), handle);
|
||||
}
|
||||
meta.sessions.forEach(function(x) {
|
||||
if (/output/.test(x.name)) return;
|
||||
var label = x.name + "\t(" + x.width + "x" + x.height + ")\t" + x.clientCount + " connected clients";
|
||||
menus.addItemByPath(SESSIONS_MENU + menus.escape(label),
|
||||
new ui.item({ value: x, class: x.name == currentName ? "strong" : "" }), handle);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
"onitemclick": function(e) {
|
||||
var options = e.relatedNode.value;
|
||||
if (options) {
|
||||
var id = options.name;
|
||||
tabs.getTabs().some(function(tab) {
|
||||
if (tab.editorType == "terminal" || tab.editorType == "output") {
|
||||
if (tab.document.getSession() && tab.document.getSession().id == id) {
|
||||
tabs.focusTab(tab);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}) || tabs.open({
|
||||
editorType: /output/.test(id) ? "output" : "terminal",
|
||||
document: { terminal: { id: id } },
|
||||
focus: true,
|
||||
pane: tabs.focussedTab.pane
|
||||
});
|
||||
}
|
||||
}
|
||||
}), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Other sessions/Loading...", new ui.item({ disabled: "true" }), 0, handle);
|
||||
|
||||
if (c9.platform != "win32") {
|
||||
menus.addItemByPath("context/terminal/Tmux/", new ui.menu(), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/~", new ui.divider({}), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Detach Other Clients", new ui.item({
|
||||
command: "term_detach" }), c += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Hint: Use Alt To Toggle Mouse Mode", new ui.item({
|
||||
disabled: "true" }), c += 100, handle);
|
||||
|
||||
var c1 = 0;
|
||||
menus.addItemByPath("context/terminal/Tmux/Close Active Pane", new ui.item({
|
||||
command: "close_term_pane" }), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/Split Active Pane", new ui.item({
|
||||
command: "split_term_pane" }), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/~", new ui.divider({}), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/Horizontal Layout (even)", new ui.item({
|
||||
command: "layout_term_hor_even" }), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/Vertical Layout (even)", new ui.item({
|
||||
command: "layout_term_ver_even" }), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/Horizonal Layout (main)", new ui.item({
|
||||
command: "layout_term_hor_main" }), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/Vertical Layout (main)", new ui.item({
|
||||
command: "layout_term_ver_main" }), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/~", new ui.divider({}), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/Toggle Status Bar", new ui.item({
|
||||
command: "toggle_term_status" }), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/~", new ui.divider({}), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/Restart All Terminal Sessions", new ui.item({
|
||||
command: "term_restart" }), c1 += 100, handle);
|
||||
menus.addItemByPath("context/terminal/Tmux/Show More Terminal Commands...", new ui.item({
|
||||
command: "term_help" }), c1 += 100, handle);
|
||||
}
|
||||
menus.addItemByPath("context/terminal/Hint: Use Alt To Toggle Mouse Mode", new ui.item({ disabled: "true" }), c += 100, handle);
|
||||
mnuTerminal = menus.get("context/terminal").menu;
|
||||
|
||||
handle.draw = function() {};
|
||||
};
|
||||
|
|
|
@ -57,7 +57,7 @@ define(function(require, exports, module) {
|
|||
name: "removefavorite",
|
||||
isAvailable: function() {
|
||||
return tree && tree.selectedNode
|
||||
&& isFavoriteNode(tree.selectedNode);
|
||||
&& isFavoritePath(tree.selectedNode.path);
|
||||
},
|
||||
exec: function() {
|
||||
tree.selectedNodes.forEach(function(node) {
|
||||
|
|
Ładowanie…
Reference in New Issue