check to code-server-like
This commit is contained in:
@@ -32,10 +32,10 @@ def realtime_response(config: dict, realtime_action: dict) -> None:
|
|||||||
|
|
||||||
elif rtype == "activeFile":
|
elif rtype == "activeFile":
|
||||||
file_path = realtime_action.get("filePath")
|
file_path = realtime_action.get("filePath")
|
||||||
assert isinstance(file_path, str)
|
|
||||||
with open(file_path, "r", encoding="utf-8") as f:
|
|
||||||
bb.active_file_content = f.read()
|
|
||||||
bb.active_file_path = file_path
|
bb.active_file_path = file_path
|
||||||
|
assert isinstance(file_path, str)
|
||||||
|
with open(os.path.join(bb.root_path, bb.active_file_content), "r", encoding="utf-8") as f:
|
||||||
|
bb.active_file_content = f.read()
|
||||||
|
|
||||||
elif rtype == "paste":
|
elif rtype == "paste":
|
||||||
file_path = realtime_action.get("filePath")
|
file_path = realtime_action.get("filePath")
|
||||||
@@ -43,14 +43,14 @@ def realtime_response(config: dict, realtime_action: dict) -> None:
|
|||||||
bb.pasted_file_path = file_path
|
bb.pasted_file_path = file_path
|
||||||
bb.pasted_content = realtime_action.get("content")
|
bb.pasted_content = realtime_action.get("content")
|
||||||
bb.active_file_path = file_path
|
bb.active_file_path = file_path
|
||||||
with open(file_path, "r", encoding="utf-8") as f:
|
with open(os.path.join(bb.root_path, bb.active_file_content), "r", encoding="utf-8") as f:
|
||||||
bb.active_file_content = f.read()
|
bb.active_file_content = f.read()
|
||||||
|
|
||||||
elif rtype == "fileEdit":
|
elif rtype == "fileEdit":
|
||||||
file_path = realtime_action.get("filePath")
|
file_path = realtime_action.get("filePath")
|
||||||
assert isinstance(file_path, str)
|
assert isinstance(file_path, str)
|
||||||
bb.active_file_path = file_path
|
bb.active_file_path = file_path
|
||||||
with open(file_path, "r", encoding="utf-8") as f:
|
with open(os.path.join(bb.root_path, bb.active_file_content), "r", encoding="utf-8") as f:
|
||||||
bb.active_file_content = f.read()
|
bb.active_file_content = f.read()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.chat-message {
|
.chat-message {
|
||||||
max-width: 70%;
|
max-width: 95%;
|
||||||
padding: 10px 15px;
|
padding: 10px 15px;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
/* 主容器,使用 grid 布局 */
|
/* 主容器,使用 grid 布局 */
|
||||||
#maxcontainer {
|
#maxcontainer {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 2fr 5px 3fr 5px 1fr; /* 默认宽度比例 */
|
grid-template-columns: 2fr 5px 3fr 5px 2fr; /* 默认宽度比例 */
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,10 +134,10 @@
|
|||||||
document.addEventListener('mousemove', function(e) {
|
document.addEventListener('mousemove', function(e) {
|
||||||
if (isDraggingLeft) {
|
if (isDraggingLeft) {
|
||||||
leftWidth = e.clientX; // 更新左侧栏宽度
|
leftWidth = e.clientX; // 更新左侧栏宽度
|
||||||
container.style.gridTemplateColumns = `${leftWidth}px 5px 1fr 5px ${rightWidth}px`;
|
container.style.gridTemplateColumns = `${leftWidth}px 5px 2fr 5px ${rightWidth}px`;
|
||||||
} else if (isDraggingRight) {
|
} else if (isDraggingRight) {
|
||||||
rightWidth = window.innerWidth - e.clientX; // 更新右侧栏宽度
|
rightWidth = window.innerWidth - e.clientX; // 更新右侧栏宽度
|
||||||
container.style.gridTemplateColumns = `${leftWidth}px 5px 1fr 5px ${rightWidth}px`;
|
container.style.gridTemplateColumns = `${leftWidth}px 5px 2fr 5px ${rightWidth}px`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -61,8 +61,7 @@ class Backboard:
|
|||||||
|
|
||||||
|
|
||||||
def get_active_file_reletive_path(self):
|
def get_active_file_reletive_path(self):
|
||||||
relative_path = os.path.relpath(self.active_file_path, self.root_path)
|
return self.active_file_path
|
||||||
return relative_path
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ def save_file():
|
|||||||
if not os.path.exists(filepath):
|
if not os.path.exists(filepath):
|
||||||
return jsonify({"error": "File not found"}), 404
|
return jsonify({"error": "File not found"}), 404
|
||||||
try:
|
try:
|
||||||
|
print(f"savefile {filepath} \n content{content}")
|
||||||
with open(filepath, 'w') as file:
|
with open(filepath, 'w') as file:
|
||||||
file.write(content)
|
file.write(content)
|
||||||
return jsonify({"message": "File saved successfully"})
|
return jsonify({"message": "File saved successfully"})
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 可以根据需要设置按钮的大小和间距 */
|
/* 可以根据需要设置按钮的大小和间距 */
|
||||||
#newFileBtn, #newFolderBtn, #toggleSearchBtn, #refreshBtn {
|
#newFileBtn, #newFolderBtn, #toggleSearchBtn, #refreshBtn, #openTerminalBtn, #saveBtn {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,24 @@
|
|||||||
let vs_socket = null;
|
let vs_socket = null;
|
||||||
|
let debounceTimeout;
|
||||||
|
|
||||||
|
// 缓冲器函数(防抖)
|
||||||
|
function debounceSendToServer(data, delay) {
|
||||||
|
if (debounceTimeout) {
|
||||||
|
clearTimeout(debounceTimeout);
|
||||||
|
}
|
||||||
|
debounceTimeout = setTimeout(() => {
|
||||||
|
sendToServer(data);
|
||||||
|
}, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function sendToServer(data){
|
function sendToServer(data){
|
||||||
try {
|
try {
|
||||||
if (!vs_socket) {
|
if (!vs_socket) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log('Sending data to Flask server:', data);
|
||||||
vs_socket.emit('message', data)
|
vs_socket.emit('message', data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error sending data to Flask server:', error);
|
console.error('Error sending data to Flask server:', error);
|
||||||
@@ -42,16 +57,7 @@ vs_socket.on('disconnect', () => {
|
|||||||
});
|
});
|
||||||
vs_socket.on('terminal',(data)=>{
|
vs_socket.on('terminal',(data)=>{
|
||||||
// vscode.window.showInformationMessage('Terminal command received'+data);
|
// vscode.window.showInformationMessage('Terminal command received'+data);
|
||||||
term.write(data.data);
|
socket.emit("pty_input", {"input": data.data+'\r\n'}, function(response) {
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// 缓冲器函数(防抖)
|
|
||||||
function debounceSendToServer(data, delay) {
|
|
||||||
if (debounceTimeout) {
|
|
||||||
clearTimeout(debounceTimeout);
|
|
||||||
}
|
|
||||||
debounceTimeout = setTimeout(() => {
|
|
||||||
sendToServer(data);
|
|
||||||
}, delay);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
let term = null;
|
let term = null;
|
||||||
|
let socket=null;
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
Terminal.applyAddon(fullscreen)
|
Terminal.applyAddon(fullscreen)
|
||||||
Terminal.applyAddon(fit)
|
Terminal.applyAddon(fit)
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const socket = io('https://hsamooc.com/vsc-like',{path:'/vsc-like-ws'});
|
socket = io('https://hsamooc.com/vsc-like',{path:'/vsc-like-ws'});
|
||||||
const status = document.getElementById("status")
|
const status = document.getElementById("status")
|
||||||
|
|
||||||
socket.on("pty_output", function(data){
|
socket.on("pty_output", function(data){
|
||||||
|
|||||||
@@ -106,7 +106,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 防抖处理非粘贴的编辑操作
|
// 防抖处理非粘贴的编辑操作
|
||||||
const content = event.document.getText();
|
const content = changes.text;
|
||||||
debounceSendToServer({
|
debounceSendToServer({
|
||||||
type: 'fileEdit',
|
type: 'fileEdit',
|
||||||
filePath: filePath,
|
filePath: filePath,
|
||||||
@@ -155,23 +155,29 @@
|
|||||||
}
|
}
|
||||||
let socket = null;
|
let socket = null;
|
||||||
function openTerminal(event) {
|
function openTerminal(event) {
|
||||||
event.stopPropagation();
|
// document.getElementById('terminal').style.display = 'block';
|
||||||
const terminalDiv = document.getElementById('terminal');
|
if (document.getElementById('terminal').style.display === 'none' || document.getElementById('terminal').style.display === '') {
|
||||||
terminalDiv.style.display = (terminalDiv.style.display === 'none' || terminalDiv.style.display === '') ? 'block' : 'none';
|
document.getElementById('terminal').style.display = 'block';
|
||||||
if (socket == null) {
|
}else{
|
||||||
socket = io.connect('http://' + document.domain + ':5200/vsc-like/terminal');
|
document.getElementById('terminal').style.display = 'none';
|
||||||
}
|
}
|
||||||
socket.on('connected', function(data) {
|
// event.stopPropagation();
|
||||||
console.log('Terminal connected');
|
// const terminalDiv = document.getElementById('terminal');
|
||||||
});
|
// terminalDiv.style.display = (terminalDiv.style.display === 'none' || terminalDiv.style.display === '') ? 'block' : 'none';
|
||||||
socket.on('terminal_output', function(data) {
|
// if (socket == null) {
|
||||||
const terminalDiv = document.getElementById('terminal');
|
// socket = io.connect('http://' + document.domain + ':5200/vsc-like/terminal');
|
||||||
terminalDiv.textContent += data.data;
|
// }
|
||||||
});
|
// socket.on('connected', function(data) {
|
||||||
|
// console.log('Terminal connected');
|
||||||
|
// });
|
||||||
|
// socket.on('terminal_output', function(data) {
|
||||||
|
// const terminalDiv = document.getElementById('terminal');
|
||||||
|
// terminalDiv.textContent += data.data;
|
||||||
|
// });
|
||||||
|
|
||||||
function sendTerminalInput(input) {
|
// function sendTerminalInput(input) {
|
||||||
socket.emit('send_input', { input: input });
|
// socket.emit('send_input', { input: input });
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按钮绑定事件
|
// 按钮绑定事件
|
||||||
|
|||||||
Reference in New Issue
Block a user