Scroll on text input
This commit is contained in:
parent
f9f7904117
commit
7f181d0e64
3 changed files with 27 additions and 22 deletions
|
|
@ -152,7 +152,7 @@ impl cosmic::Application for App {
|
|||
let terminal = terminal.lock().unwrap();
|
||||
let rgb = terminal.colors()[index].unwrap_or_default();
|
||||
let text = f(rgb);
|
||||
terminal.input(text.into_bytes());
|
||||
terminal.input_no_scroll(text.into_bytes());
|
||||
}
|
||||
}
|
||||
TermEvent::Exit => {
|
||||
|
|
@ -161,7 +161,7 @@ impl cosmic::Application for App {
|
|||
TermEvent::PtyWrite(text) => {
|
||||
if let Some(terminal) = self.tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
let terminal = terminal.lock().unwrap();
|
||||
terminal.input(text.into_bytes());
|
||||
terminal.input_no_scroll(text.into_bytes());
|
||||
}
|
||||
}
|
||||
TermEvent::ResetTitle => {
|
||||
|
|
@ -172,7 +172,7 @@ impl cosmic::Application for App {
|
|||
if let Some(terminal) = self.tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
let terminal = terminal.lock().unwrap();
|
||||
let text = f(terminal.size().into());
|
||||
terminal.input(text.into_bytes());
|
||||
terminal.input_no_scroll(text.into_bytes());
|
||||
}
|
||||
}
|
||||
TermEvent::Title(title) => {
|
||||
|
|
|
|||
|
|
@ -290,10 +290,15 @@ impl Terminal {
|
|||
self.with_buffer_mut(|buffer| buffer.set_redraw(redraw));
|
||||
}
|
||||
|
||||
pub fn input<I: Into<Cow<'static, [u8]>>>(&self, input: I) {
|
||||
pub fn input_no_scroll<I: Into<Cow<'static, [u8]>>>(&self, input: I) {
|
||||
self.notifier.notify(input);
|
||||
}
|
||||
|
||||
pub fn input_scroll<I: Into<Cow<'static, [u8]>>>(&self, input: I) {
|
||||
self.input_no_scroll(input);
|
||||
self.scroll(TerminalScroll::Bottom);
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, width: u32, height: u32, scale_factor: f32) {
|
||||
//TODO: check scale factor
|
||||
if width != self.size.width || height != self.size.height {
|
||||
|
|
|
|||
|
|
@ -319,46 +319,46 @@ where
|
|||
modifiers,
|
||||
}) => match key_code {
|
||||
KeyCode::Backspace => {
|
||||
terminal.input(b"\x08".as_slice());
|
||||
terminal.input_scroll(b"\x08".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Tab => {
|
||||
if modifiers.shift() {
|
||||
terminal.input(b"\x1B[Z".as_slice());
|
||||
terminal.input_scroll(b"\x1B[Z".as_slice());
|
||||
} else {
|
||||
terminal.input(b"\t".as_slice());
|
||||
terminal.input_scroll(b"\t".as_slice());
|
||||
}
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
terminal.input(b"\n".as_slice());
|
||||
terminal.input_scroll(b"\n".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Escape => {
|
||||
terminal.input(b"\x1B".as_slice());
|
||||
terminal.input_scroll(b"\x1B".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Up => {
|
||||
terminal.input(b"\x1B[A".as_slice());
|
||||
terminal.input_scroll(b"\x1B[A".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Down => {
|
||||
terminal.input(b"\x1B[B".as_slice());
|
||||
terminal.input_scroll(b"\x1B[B".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Right => {
|
||||
terminal.input(b"\x1B[C".as_slice());
|
||||
terminal.input_scroll(b"\x1B[C".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Left => {
|
||||
terminal.input(b"\x1B[D".as_slice());
|
||||
terminal.input_scroll(b"\x1B[D".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::End => {
|
||||
if modifiers.shift() {
|
||||
terminal.scroll(TerminalScroll::Bottom);
|
||||
} else {
|
||||
terminal.input(b"\x1B[F".as_slice());
|
||||
terminal.input_scroll(b"\x1B[F".as_slice());
|
||||
}
|
||||
status = Status::Captured;
|
||||
}
|
||||
|
|
@ -366,23 +366,23 @@ where
|
|||
if modifiers.shift() {
|
||||
terminal.scroll(TerminalScroll::Top);
|
||||
} else {
|
||||
terminal.input(b"\x1B[H".as_slice());
|
||||
terminal.input_scroll(b"\x1B[H".as_slice());
|
||||
}
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Insert => {
|
||||
terminal.input(b"\x1B[2~".as_slice());
|
||||
terminal.input_scroll(b"\x1B[2~".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::Delete => {
|
||||
terminal.input(b"\x1B[3~".as_slice());
|
||||
terminal.input_scroll(b"\x1B[3~".as_slice());
|
||||
status = Status::Captured;
|
||||
}
|
||||
KeyCode::PageUp => {
|
||||
if modifiers.shift() {
|
||||
terminal.scroll(TerminalScroll::PageUp);
|
||||
} else {
|
||||
terminal.input(b"\x1B[5~".as_slice());
|
||||
terminal.input_scroll(b"\x1B[5~".as_slice());
|
||||
}
|
||||
status = Status::Captured;
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ where
|
|||
if modifiers.shift() {
|
||||
terminal.scroll(TerminalScroll::PageDown);
|
||||
} else {
|
||||
terminal.input(b"\x1B[6~".as_slice());
|
||||
terminal.input_scroll(b"\x1B[6~".as_slice());
|
||||
}
|
||||
status = Status::Captured;
|
||||
}
|
||||
|
|
@ -414,7 +414,7 @@ where
|
|||
if character.is_control() {
|
||||
let mut buf = [0, 0, 0, 0];
|
||||
let str = character.encode_utf8(&mut buf);
|
||||
terminal.input(str.as_bytes().to_vec());
|
||||
terminal.input_scroll(str.as_bytes().to_vec());
|
||||
}
|
||||
}
|
||||
(false, false, true) => {
|
||||
|
|
@ -422,7 +422,7 @@ where
|
|||
// Handle alt for non-control characters
|
||||
let mut buf = [0x1B, 0, 0, 0, 0];
|
||||
let str = character.encode_utf8(&mut buf[1..]);
|
||||
terminal.input(str.as_bytes().to_vec());
|
||||
terminal.input_scroll(str.as_bytes().to_vec());
|
||||
}
|
||||
}
|
||||
(false, false, false) => {
|
||||
|
|
@ -430,7 +430,7 @@ where
|
|||
if !character.is_control() {
|
||||
let mut buf = [0, 0, 0, 0];
|
||||
let str = character.encode_utf8(&mut buf);
|
||||
terminal.input(str.as_bytes().to_vec());
|
||||
terminal.input_scroll(str.as_bytes().to_vec());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue