mirror of https://github.com/lapce/lapce.git
termainl pty send
This commit is contained in:
parent
13269f0a23
commit
1ef920b19f
|
@ -155,6 +155,16 @@ pub fn new_terminal(&self, term_id: TermId, width: usize, height: usize) {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn terminal_insert(&self, term_id: TermId, s: &str) {
|
||||
self.peer.lock().as_ref().unwrap().send_rpc_notification(
|
||||
"terminal_insert",
|
||||
&json!({
|
||||
"term_id": term_id,
|
||||
"content": s,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn terminal_resize(&self, term_id: TermId, width: usize, height: usize) {
|
||||
self.peer.lock().as_ref().unwrap().send_rpc_notification(
|
||||
"terminal_resize",
|
||||
|
|
|
@ -231,7 +231,7 @@ fn event(
|
|||
.terminals
|
||||
.get_mut(id)
|
||||
.unwrap();
|
||||
terminal.content = content.to_owned();
|
||||
Arc::make_mut(terminal).content = content.to_owned();
|
||||
ctx.set_handled();
|
||||
}
|
||||
LapceUICommand::UpdateDiffFiles(files) => {
|
||||
|
|
|
@ -11,15 +11,17 @@
|
|||
use crate::{
|
||||
config::LapceTheme,
|
||||
data::LapceTabData,
|
||||
keypress::KeyPressFocus,
|
||||
proxy::{LapceProxy, TerminalContent},
|
||||
split::LapceSplitNew,
|
||||
state::Mode,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TerminalSplitData {
|
||||
pub widget_id: WidgetId,
|
||||
pub split_id: WidgetId,
|
||||
pub terminals: im::HashMap<TermId, LapceTerminalData>,
|
||||
pub terminals: im::HashMap<TermId, Arc<LapceTerminalData>>,
|
||||
}
|
||||
|
||||
impl TerminalSplitData {
|
||||
|
@ -27,7 +29,7 @@ pub fn new(proxy: Arc<LapceProxy>) -> Self {
|
|||
let split_id = WidgetId::next();
|
||||
let mut terminals = im::HashMap::new();
|
||||
|
||||
let terminal = LapceTerminalData::new(proxy);
|
||||
let terminal = Arc::new(LapceTerminalData::new(proxy));
|
||||
terminals.insert(terminal.id, terminal);
|
||||
|
||||
Self {
|
||||
|
@ -38,6 +40,34 @@ pub fn new(proxy: Arc<LapceProxy>) -> Self {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct LapceTerminalViewData {
|
||||
terminal: Arc<LapceTerminalData>,
|
||||
proxy: Arc<LapceProxy>,
|
||||
}
|
||||
|
||||
impl KeyPressFocus for LapceTerminalViewData {
|
||||
fn get_mode(&self) -> Mode {
|
||||
Mode::Insert
|
||||
}
|
||||
|
||||
fn check_condition(&self, condition: &str) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn run_command(
|
||||
&mut self,
|
||||
ctx: &mut EventCtx,
|
||||
command: &crate::command::LapceCommand,
|
||||
count: Option<usize>,
|
||||
env: &Env,
|
||||
) {
|
||||
}
|
||||
|
||||
fn insert(&mut self, ctx: &mut EventCtx, c: &str) {
|
||||
self.proxy.terminal_insert(self.terminal.id, c);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LapceTerminalData {
|
||||
id: TermId,
|
||||
|
@ -48,7 +78,7 @@ impl LapceTerminalData {
|
|||
pub fn new(proxy: Arc<LapceProxy>) -> Self {
|
||||
let id = TermId::next();
|
||||
std::thread::spawn(move || {
|
||||
proxy.new_terminal(id, 1, 1);
|
||||
proxy.new_terminal(id, 50, 20);
|
||||
});
|
||||
Self {
|
||||
id,
|
||||
|
@ -169,6 +199,33 @@ fn event(
|
|||
data: &mut LapceTabData,
|
||||
env: &Env,
|
||||
) {
|
||||
let old_terminal_data =
|
||||
data.terminal.terminals.get(&self.term_id).unwrap().clone();
|
||||
let mut term_data = LapceTerminalViewData {
|
||||
terminal: old_terminal_data.clone(),
|
||||
proxy: data.proxy.clone(),
|
||||
};
|
||||
match event {
|
||||
Event::MouseDown(mouse_event) => {
|
||||
ctx.request_focus();
|
||||
}
|
||||
Event::KeyDown(key_event) => {
|
||||
let mut keypress = data.keypress.clone();
|
||||
Arc::make_mut(&mut keypress).key_down(
|
||||
ctx,
|
||||
key_event,
|
||||
&mut term_data,
|
||||
env,
|
||||
);
|
||||
data.keypress = keypress.clone();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
if !term_data.terminal.same(&old_terminal_data) {
|
||||
Arc::make_mut(&mut data.terminal)
|
||||
.terminals
|
||||
.insert(term_data.terminal.id, term_data.terminal.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn lifecycle(
|
||||
|
|
|
@ -124,6 +124,10 @@ pub enum Notification {
|
|||
height: usize,
|
||||
term_id: TermId,
|
||||
},
|
||||
TerminalInsert {
|
||||
term_id: TermId,
|
||||
content: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
@ -413,6 +417,11 @@ fn handle_notification(&self, rpc: Notification) {
|
|||
self.lsp.lock().update(buffer, &content_change, buffer.rev);
|
||||
}
|
||||
}
|
||||
Notification::TerminalInsert { term_id, content } => {
|
||||
if let Some(terminal) = self.terminals.lock().get(&term_id) {
|
||||
terminal.insert(content);
|
||||
}
|
||||
}
|
||||
Notification::TerminalResize {
|
||||
term_id,
|
||||
width,
|
||||
|
|
|
@ -124,6 +124,7 @@ fn run(&self, receiver: Receiver<Event>, notifier: Notifier) {
|
|||
Event::ClipboardLoad(_, _) => {}
|
||||
Event::ColorRequest(_, _) => {}
|
||||
Event::PtyWrite(s) => {
|
||||
eprintln!("pty write {}", s);
|
||||
notifier.notify(s.into_bytes());
|
||||
}
|
||||
Event::CursorBlinkingChange(_) => {}
|
||||
|
|
Loading…
Reference in New Issue