增加本地终端
This commit is contained in:
parent
e561439b4d
commit
2965a9283d
@ -1,10 +1,9 @@
|
||||
package org.jcnc.jnotepad.ui.module;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import org.fxmisc.richtext.CodeArea;
|
||||
import org.fxmisc.richtext.LineNumberFactory;
|
||||
|
||||
@ -13,13 +12,20 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* 终端仿真器组件,用于执行命令并显示输出。
|
||||
* <p>
|
||||
* 该组件包括一个用于输入命令的文本字段和一个显示命令输出的CodeArea。
|
||||
* 用户可以在文本字段中输入命令,按回车键执行,并在CodeArea中查看输出。
|
||||
*
|
||||
* @author luke
|
||||
*/
|
||||
public class TerminalEmulatorComponent extends VBox {
|
||||
public class TerminalEmulatorComponent extends BorderPane {
|
||||
|
||||
private CodeArea terminalOutput;
|
||||
private Process process;
|
||||
|
||||
/**
|
||||
* 创建一个新的终端仿真器组件。
|
||||
*/
|
||||
public TerminalEmulatorComponent() {
|
||||
init();
|
||||
}
|
||||
@ -39,18 +45,15 @@ public class TerminalEmulatorComponent extends VBox {
|
||||
}
|
||||
});
|
||||
|
||||
getChildren().addAll(terminalOutput, commandInput);
|
||||
setAlignment(Pos.CENTER);
|
||||
|
||||
// 设置布局样式和大小
|
||||
setSpacing(10);
|
||||
setCenter(terminalOutput);
|
||||
setBottom(commandInput);
|
||||
}
|
||||
|
||||
private void executeCommand(String command) {
|
||||
try {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
|
||||
processBuilder.redirectErrorStream(true);
|
||||
process = processBuilder.start();
|
||||
Process process = processBuilder.start();
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"));
|
||||
String line;
|
||||
|
||||
@ -2,7 +2,6 @@ package org.jcnc.jnotepad.views.root.bottom;
|
||||
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.jcnc.jnotepad.ui.module.AbstractVerticalBox;
|
||||
import org.jcnc.jnotepad.ui.module.TerminalEmulatorComponent;
|
||||
import org.jcnc.jnotepad.views.root.bottom.cmd.CmdStatusBox;
|
||||
import org.jcnc.jnotepad.views.root.bottom.status.BottomStatusBox;
|
||||
|
||||
@ -29,10 +28,7 @@ public class RootBottomSideBarVerticalBox extends AbstractVerticalBox {
|
||||
public void initSidebarVerticalBox() {
|
||||
bottomSideBarVerticalBox = new VBox();
|
||||
|
||||
TerminalEmulatorComponent terminal = new TerminalEmulatorComponent();
|
||||
|
||||
|
||||
bottomSideBarVerticalBox.getChildren().addAll(terminal,CmdStatusBox.getInstance(), BottomStatusBox.getInstance());
|
||||
bottomSideBarVerticalBox.getChildren().addAll(CmdStatusBox.getInstance(), BottomStatusBox.getInstance());
|
||||
|
||||
|
||||
getChildren().addAll(bottomSideBarVerticalBox);
|
||||
@ -45,13 +41,4 @@ public class RootBottomSideBarVerticalBox extends AbstractVerticalBox {
|
||||
initSidebarVerticalBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 bottomSideBarVerticalBox 实例。
|
||||
*
|
||||
* @return bottomSideBarVerticalBox 的实例
|
||||
*/
|
||||
public VBox getBottomSideBarVerticalBox() {
|
||||
return bottomSideBarVerticalBox;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,18 +1,29 @@
|
||||
package org.jcnc.jnotepad.views.root.bottom.cmd;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.MenuBar;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.stage.Stage;
|
||||
import org.jcnc.jnotepad.ui.module.TerminalEmulatorComponent;
|
||||
import org.jcnc.jnotepad.util.UiUtil;
|
||||
|
||||
/**
|
||||
* CmdStatusBox 类表示应用程序的命令状态框。
|
||||
* <p>
|
||||
* 该框包括一个菜单栏,用于运行、终端和构建命令。用户可以点击终端菜单项以切换终端的显示状态。
|
||||
* 终端显示时,将创建一个新的窗口以显示终端模拟器组件。
|
||||
*
|
||||
* @author luke
|
||||
*/
|
||||
public class CmdStatusBox extends HBox {
|
||||
|
||||
Stage terminalStage = new Stage();
|
||||
|
||||
private static final CmdStatusBox CMD_STATUS_BOX = new CmdStatusBox();
|
||||
|
||||
/**
|
||||
@ -24,10 +35,18 @@ public class CmdStatusBox extends HBox {
|
||||
initStatusBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 CmdStatusBox 的实例。
|
||||
*
|
||||
* @return CmdStatusBox 的实例
|
||||
*/
|
||||
public static CmdStatusBox getInstance() {
|
||||
return CMD_STATUS_BOX;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化命令状态框。
|
||||
*/
|
||||
public void initStatusBox() {
|
||||
var menuBar = new MenuBar();
|
||||
HBox.setHgrow(menuBar, Priority.ALWAYS);
|
||||
@ -53,21 +72,47 @@ public class CmdStatusBox extends HBox {
|
||||
this.getChildren().add(menuBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换终端的显示/隐藏状态。
|
||||
*/
|
||||
private void toggleTerminal() {
|
||||
if (terminalVisible) {
|
||||
// 隐藏终端
|
||||
terminalVisible = false;
|
||||
// 在这里添加隐藏终端的代码
|
||||
hideTerminal();
|
||||
} else {
|
||||
// 显示终端
|
||||
terminalVisible = true;
|
||||
showTerminal(); // 显示终端
|
||||
showTerminal();
|
||||
}
|
||||
}
|
||||
|
||||
private void showTerminal() {
|
||||
TerminalEmulatorComponent terminal = new TerminalEmulatorComponent();
|
||||
// 在这里添加显示终端的代码
|
||||
/**
|
||||
* 隐藏终端窗口。
|
||||
*/
|
||||
private void hideTerminal() {
|
||||
terminalStage.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示终端窗口。
|
||||
*/
|
||||
private void showTerminal() {
|
||||
// 创建一个新的舞台(窗口)
|
||||
terminalStage.setTitle("终端");
|
||||
terminalStage.getIcons().add(UiUtil.getAppIcon());
|
||||
|
||||
// 创建一个根节点(布局)
|
||||
BorderPane root = new BorderPane();
|
||||
Scene scene = new Scene(root, UiUtil.getAppWindow().getWidth() - 50, UiUtil.getAppWindow().getHeight() / 3);
|
||||
|
||||
// 创建TerminalEmulatorComponent并添加到根节点
|
||||
TerminalEmulatorComponent terminal = new TerminalEmulatorComponent();
|
||||
|
||||
root.setCenter(terminal);
|
||||
terminalStage.setScene(scene);
|
||||
|
||||
// 显示窗口
|
||||
terminalStage.show();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user